- 论坛徽章:
- 0
|
每天早上都要听美国总统电台演说,都没有保存资料。昨天上班上的郁闷特写一个python脚本自动抓取并保存该资料,python真是强大。从学到整个东西写完只用了1个多小时,去掉页面上的大量广告,只留下所需信息,自动保存为html文件。程序很简单,就不错说了看代码
import sys,urllib
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=")+7:content.find("target")-2]
filename = content
url ="http://www.putclub.com/"+content
print content
print url
wp = urllib.urlopen(url)
print "start download..."
content = wp.read()
#print content
print content.count(""):]
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)
fp.close()
print content
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/93893/showart_2125208.html |
|