2008/09/26

第一个python程序

# search IMDB TOP 250 in VeryCD 
# Author: chenqian
# URL: www.stopdesign.cn

import urllib2
from BeautifulSoup import BeautifulSoup

page = urllib2.urlopen("http://www.imdb.com/chart/top")
soup = BeautifulSoup(page.read())
div=soup("table")[11]
vcurl=''
for i in div:
movies = i.contents[2].contents[0].contents[0].contents[0]
#print movies
vcurl+="<a href='http://www.verycd.com/search/folders/"+movies+"'>"+movies+"</a><br />\n"
# age print i.contents[2].contents[0].contents[1]

filename = "top250.html"
file = open(filename, 'w')
file.write(vcurl)
file.close()

用到了beautiful soup,结果在:top250.html

Labels:

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home