Beautiful Soup Nested Tag Search

后端 未结 3 609
孤城傲影
孤城傲影 2021-01-12 04:35

I am trying to write a python program that will count the words on a web page. I use Beautiful Soup 4 to scrape the page but I have difficulties accessing nested HTML tags (

3条回答
  •  执笔经年
    2021-01-12 05:38

    Try this one :

    data = []
    for nested_soup in soup.find_all('xyz'):
        data = data + nested_soup.find_all('abc')
    # data holds all shit together
    

    Maybe you can turn in into lambda and make it cool, but this works. Thanks.

提交回复
热议问题