Beautiful Soup find children for particular div

前端 未结 1 846
迷失自我
迷失自我 2021-01-31 08:19

I have am trying to parse a webpage that looks like this with Python->Beautiful Soup:\"enter<

相关标签:
1条回答
  • 2021-01-31 09:09

    It is useful to know that whatever elements BeautifulSoup finds within one element still have the same type as that parent element - that is, various methods can be called.

    So this is somewhat working code for your example:

    soup = BeautifulSoup(html)
    divTag = soup.find_all("div", {"class": "tablebox"})
    
    for tag in divTag:
        tdTags = tag.find_all("td", {"class": "align-right"})
        for tag in tdTags:
            print tag.text
    

    This will print all the text of all the td tags with the class of "align-right" that have a parent div with the class of "tablebox".

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