Find a specific tag with BeautifulSoup

后端 未结 2 1223
野性不改
野性不改 2020-12-09 15:51

I can traverse generic tags easily with BS, but I don\'t know how to find specific tags. For example, how can I find all occurances of

相关标签:
2条回答
  • 2020-12-09 16:38

    with bs4 things have changed a little. so the code should look like this

    soup = BeautifulSoup(htmlstring,'lxml') soup.find_all('div', {'style':"width=300px;"})

    0 讨论(0)
  • 2020-12-09 16:55

    The following should work

    soup = BeautifulSoup(htmlstring)
    soup.findAll('div', style="width=300px;")
    

    There are couple of ways to search for tags.

    • http://www.crummy.com/software/BeautifulSoup/documentation.html

    For more text to understand and use it

    • http://lxml.de/elementsoup.html
    0 讨论(0)
提交回复
热议问题