Getting the value of href attributes in all tags on a html file with Python

</p> <p><code>from BeautifulSoup import BeautifulSoup as soup<br>html = soup('&lt;body&gt;&lt;a href="123"&gt;qwe&lt;/a&gt;&lt;a href="456"&gt;asd&lt;/a&gt;&lt;/body&gt;')<br>print [tag.attrMap['href'] for tag in html.findAll('a', {'href': True})]</code></p> <p><code></code>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: