i have 2 cases want scrape html custom html attributes example of html. how scrape elements custom attribute "limit".
<div class="names" limit="10">bar</div> <div id="30" limit="20">foo</div> <li limit="x">baz</li> the second case similar same html tags
<div class="names" limit="10">bar</div> <div class="names" limit="20">bar</div> <div class="names" limit="30">bar</div> my question different how find tags attributes - beautifulsoup because latter targets attribute values specific tag whereas former(my question) looks target attribute despite tag or value
# 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 attribute name doesn't collide either python keywords or soup.find_all named args, syntax simpler:
soup.find_all(id=true)
Comments
Post a Comment