Get data from the meta tags using BeautifulSoup

前端 未结 1 1036
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 16:53

I am trying to read the description from the meta tag and this is what I used

soup.findAll(name=\"description\")

but it does not work, however,

相关标签:
1条回答
  • 2021-02-02 17:16

    Yep, name can't be used in keyword-argument form to designate an attribute named name because the name name is already used by BeautifulSoup itself. So use instead:

    soup.findAll(attrs={"name":"description"})
    

    That's what the attrs argument is for: passing as a dict those attribute constraints for which you can't use keyword-argument form because their names are Python keyword or otherwise taken by BeautifulSoup itself!

    0 讨论(0)
提交回复
热议问题