If Beautiful Soup gives me an anchor tag like this:
<a class="blah blah" id="blah blah" href="link.html"></a>
How would I retrieve the value of the href
attribute?
How do you get attribute value in BeautifulSoup? To extract attributes of elements in Beautiful Soup, use the [~] notation. For instance, el[“id”] retrieves the value of the id attribute.
If you already have the anchor, grab the href
attribute like this:
href = anchor["href"]
link.get('href')
in which 'link' is the name of your 'a' tag
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