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 "limit".
<div class="names" limit="10">Bar</div> <div id="30" limit="20">Foo</div> <li limit="x">Baz</li>
The second case is similar but with all the 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 is different than How to find tags with only certain attributes - BeautifulSoup because the latter targets attribute values with a specific tag whereas my question finds attributes only regardless of tag or value
Attributes are always specified in the start tag (or opening tag) and usually consists of name/value pairs like name="value" . Attribute values should always be enclosed in quotation marks.
Every HTML element may have any number of custom data attributes specified, with any value.
# First case: soup.find_all(attrs={"limit":True}) # Second case: soup.find_all("div", attrs={"limit":True})
Reference:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With