- 論壇徽章:
- 0
|
每天早上都要聽美國總統(tǒng)電臺演說,都沒有保存資料。昨天上班上的郁悶特寫一個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 |
|