每天早上都要听美国总统电台演说,都没有保存资料。昨天上班上的郁闷特写一个python脚本自动抓取并保存该资料,python真是强大。从学到整个东西写完只用了1个多小时,去掉页面上的大量广告,只留下所需信息,自动保存为html文件。程序很简单,就不错说了看代码
url="http://www.putclub.com/html/radio/VOA/presidentspeech/index.html"
wp = urllib.urlopen(url)
print "start download..."
content = wp.read()
print content.count("center_box")
index = content.find("center_box")
content=content[content.find("center_box")+1:]
content=content[content.find("href="/html/jishu515)+7:content.find(.html"target")-2]
filename = content
url ="http://www.putclub.com/"+content
print content
wp = urllib.urlopen(url)
print "start download..."
content = wp.read()
#print content
print content.count("<div class=\"content\"")
#content = content[content.find("<div class=\"content\""):]
content = content[content.find("<!--info end------->"):]
content = content[:content.find("<div class=\"dede_pages\"")-1]
filename = filename[filename.find("presidentspeech")+len("presidentspeech/"):]
filename = filename.replace('/',"-",filename.count("/"))
fp = open(filename,"w+")
fp.write(content)
print content
发表于: 2009-12-18 ,修改于: 2009-12-18 16:44,已浏览67次,有评论0条推荐投诉
网友评论
发表评论
此博文原地址为:http://blog.chinaunix.net/u3/93893/showart_2125208.html