10
votes

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?

2

2 Answers

10
votes

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

href = anchor["href"]
1
votes
link.get('href')

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