[Tutor] An idea for a script

Eric Walstad eric at ericwalstad.com
Wed Oct 10 23:23:23 CEST 2007


Dick Moores wrote:
> I think I could learn a lot about the use of Python with the web by 
> writing a script that would look at 
> <http://starship.python.net/crew/index.html> and find all the links 
> to more that just the default shown by this one: 
> <http://starship.python.net/crew/beazley/>. I think there should be 
> about 20 URLs in the list. But I need a start. So give me one?

BeautifulSoup?

# untested...

import urllib
from BeautifulSoup import BeautifulSoup
starship_crew_list_url = 'http://starship.python.net/crew/index.html'
starship_crew_list_html = urllib.urlopen(starship_crew_list_url).read()
soup = BeautifulSoup(starship_crew_list_html)
for anchor in soup.fetch('a'):
	print anchor

# / untested

-Eric
<http://starship.python.net/crew/ewalstad/>
should be one of the results you see :)



More information about the Tutor mailing list