Skip to content Skip to sidebar Skip to footer

Parse Html Beautiful Soup

I have a html page

Solution 1:

Your mistake was in using the attrs dict to look for elements with an email attribute that is empty. Try this instead.

#!/usr/bin/env pythonfrom BeautifulSoup import BeautifulSoup
import urllib2

req = urllib2.urlopen('http://worldnuclearwar.ru')

soup = BeautifulSoup(req)
print soup.find("a", email=True)["email"]

To print the email attribute of the firsta element which has an email attribute. If you want all emails, try

forlinkin soup.findAll("a", email=True):
    printlink["email"]

Post a Comment for "Parse Html Beautiful Soup"