女儿的寒假作业要做天气的统计图,需要得到历史的天气数据
- import sys
- import time
- from BeautifulSoup import BeautifulSoup
- import urllib
-
-
mon1=""
- mon2=""
-
- urlstr=[]
-
- for i in range(31):
-
-
tmpstr=str(i+1)
-
-
urlstr.append(mon1+tmpstr.zfill(2)+'/')
- for i in range(22):
-
-
tmpstr=str(i+1)
-
-
urlstr.append(mon2+tmpstr.zfill(2)+'/')
-
for eachurl in urlstr:
-
-
sock=urllib.urlopen(eachurl)
-
strhtml=sock.read()
-
soup=BeautifulSoup(strhtml)
-
wealist=soup.find("div","wtday")
-
print wealist.text
-
time.sleep(1)
-
- 拷贝出屏幕数据,搞定
阅读(1559) | 评论(0) | 转发(0) |