[Tutor] html links
Sönmez Kartal
sonmez at lavabit.com
Tue May 15 08:57:42 CEST 2007
Hi,
import urllib
from BeautifulSoup import BeautifulSoup
page = urllib.urlopen(url) # url is the page address, if you are reading
a file in your hard drive you could use just open(filename) too, and no
needing to urllib
soup = BeautifulSoup(page)
#links = [str(link) for link in soup.findAll('a')]
links = soup.findAll('a')
I have used list compherension, comment outed line, because findAll
function returns a different type specific to BeautifulSoup. First line,
list compherension used converts every link to string.
Happy coding...
--
Sönmez Kartal
More information about the Tutor
mailing list