使用bs,requests寫的
#coding=utf-8
import requests
import re
import argparse
from bs4 import beautifulsoup
parser = argparse.argumentparser()
parser.add_argument('-c','--city',default='hangzhou')
args = parser.parse_args()
city = args.city
url = ''+city
response = requests.get(url)
response.encoding = 'utf-8'
soup = beautifulsoup(response.text,'html.parser')
city = soup.find(class_='slider_ct_name').string.encode('utf-8')
date =
weather =
temperature =
#get date
for item in soup('p',class_='wt_fc_c0_i_date'):
#get weather
for item in soup("img", ):
#get temperature
for item in soup('p',class_='wt_fc_c0_i_temp'):
txt = ''
txt += city + '10日天氣:\n'
for counter in range(10):
txt += date[counter] +'\t' +'day:' + weather[2*counter] +'\t\t\t'+'nignt:'+weather[2*counter+1]+'\t\t'
txt += temperature[counter]
txt +='\n'
print txt
filename = city + '10日天氣'+'.txt'
with open(filename,'w') as fp:
fp.write(txt)
#注意:在晚上使用本爬蟲會出現陣列越界,原因是今天白天的天氣資料已經消失了,所以weather陣列實際上只有19個元素,稍稍改動即可
#last modified on 2016.9.25
開源乙個天氣小程式 輕鬆天氣
雖然這個小玩具掙不了錢,也沒什麼特別之處,但是對我來說意義重大,想了許久還是決定開源,可以給有需要的人做個參考。這個小程式的基本特點 目前這個小程式也還在運營 其實就是偶爾更新下 介面長這樣 點個 star 好嘛 但是理論上無論啥版本都可以正常開啟執行。本小程式裡使用的天氣資料 於第三方提供的 ap...
乙個小爬蟲
usr bin env python coding utf 8 sina小爬蟲 site http 不能少哦 reptile sina reptitle site print getting the urls.n reptile sina.get urls site reptile sina.sto...
乙個天氣預報的小應用
第一次寫部落格,以前總是固執的認為寫部落格是一件費時費勁的爛事,當看了阿杜的部落格後,突然就一種想部落格的衝動啦!也全當是記錄下自己學習過程中對某些知識的理解吧,雖然自己還是一枚小菜鳥,但自己還是想為開源社群做些小貢獻,所以就把自己寫的 都上傳到網上,希望大俠們能多給些指導。其實這個小demo還有很...