How to find all elements with a custom html attribute regardless of html tag using Beautiful Soup?

后端 未结 1 1641
死守一世寂寞
死守一世寂寞 2020-12-10 11:44

I have two cases where i want to scrape html tags with custom html attributes This is the example of the html. How do you scrape all the elements with the custom attribute

相关标签:
1条回答
  • 2020-12-10 12:30
    # First case:
    soup.find_all(attrs={"limit":True})
    
    # Second case:
    soup.find_all("div", attrs={"limit":True})
    

    Reference:

    • http://www.crummy.com/software/BeautifulSoup/bs4/doc/#kwargs
    • http://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-all

    If your attribute name doesn't collide with either Python keywords or soup.find_all named args, the syntax is simpler:

    soup.find_all(id=True)
    
    0 讨论(0)
提交回复
热议问题