db90
db90

Reputation: 115

BeautifulSoup - extracting attribute values

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?

Upvotes: 9

Views: 7300

Answers (2)

Sahba E
Sahba E

Reputation: 11

link.get('href')

in which 'link' is the name of your 'a' tag

Upvotes: 1

Andrew Hare
Andrew Hare

Reputation: 351758

If you already have the anchor, grab the href attribute like this:

href = anchor["href"]

Upvotes: 10

Related Questions