python定時器爬取豆瓣音樂Top榜歌名
作者:vpoet
日期:大約在夏季
注:這些小demo都是前段時間為了學python寫的,現在貼出來純粹是為了和大家分享一下
#coding=utf-8import urllib
import urllib2
import re
import timedef SaveTop20Music(currtime):
rex=r'<a href="javascript:;">(.*?)</a>';
url = ' Response = urllib2.urlopen(url);
Html=Response.read();
listsofsong = re.findall(rex, Html);
print len(listsofsong);
f=open('%s.txt' % currtime,'w');
x=1;
for line in listsofsong:
f.write('top'+str(x)+':'+line);
f.write('\n');
x=x+1;
f.flush();f.close(); print currtime+'.txt'+'\t\t'+'SaveOver'
def timer(n):
while True:
currtime = time.strftime("Savetime_%H-%M-%S", time.localtime())
print currtime
SaveTop20Music(currtime)
time.sleep(n)if name == "main":
timer(5)
</pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!