Ⅰ python如何提取網頁天氣信息
bs4是可以提取的,因為你這一段裡面出現的文字都是你要的,不存在剔除的考慮。
網頁解析:要麼使用bs4、要麼使用bs4+re(正則),或者你可以使用以下PyQuery,這個也是用在網頁爬蟲解析頁面的模塊。
如果還是琢磨不出來,你把你這整個的html源碼發上來,我搞搞,現在只看一段很難幫你
Ⅱ 如何使用python利用api獲取天氣預報
這個和用不用python沒啥關系,是數據來源的問題。調用淘寶API,使用 api相關介面獲得你想要的內容,我 記得api中有相關的介面,你可以看一下介面的說明。用python做爬蟲來進行頁面數據的獲取。希望能幫到你。
Ⅲ 如何利用python爬取某個地方1年的天氣
先要找到提供這個地方天氣信息的網站
然後用firefox之類的瀏覽器分析
之後用python按分析的結果來提取所需要的數據
Ⅳ python怎麼自動抓取網頁上每日天氣預報
使用到了urllib庫和bs4。bs4提供了專門針對html的解析功能,比用RE方便許多。
# coding : UTF-8import sys
reload(sys)
sys.setdefaultencoding( "utf-8" )from bs4 import BeautifulSoupimport csvimport urllibdef get_html(url):
html = urllib.urlopen(url) return html.read()def get_data(html_text):
final = []
bs = BeautifulSoup(html_text, "html.parser")
body = bs.body
data = body.find('div', {'id': '7d'})
ul = data.find('ul')
li = ul.find_all('li') for day in li:
temp = []
date = day.find('h1').string
temp.append(date)
inf = day.find_all('p')
temp.append(inf[0].string,) if inf[1].find('span') is None:
temperature_highest = None
else:
temperature_highest = inf[1].find('span').string
temperature_highest = temperature_highest.replace('C', '')
temperature_lowest = inf[1].find('i').string
temperature_lowest = temperature_lowest.replace('C', '')
temp.append(temperature_highest)
temp.append(temperature_lowest)
final.append(temp) return finaldef write_data(data, name):
file_name = name with open(file_name, 'a') as f:
f_csv = csv.writer(f)
f_csv.writerows(data)if __name__ == '__main__':
html_doc = get_html('http://www.weather.com.cn/weather/101190401.shtml')
result = get_data(html_doc)
write_data(result, 'weather.csv') print
運行結果保存在csv文件中,如下:
28日(今天),小雨,,13℃29日(明天),小雨轉陰,15℃,12℃30日(後天),多雲,19℃,14℃31日(周一),小雨,16℃,14℃1日(周二),陰轉多雲,16℃,10℃2日(周三),多雲轉晴,17℃,10℃3日(周四),多雲轉晴,18℃,11℃1234567
Ⅳ python爬蟲完成了天氣數據的爬尋,然後可以做一些什麼變復雜或者變完整
再寫個發郵件模塊,根據爬取的天氣內容判斷,提醒用戶是否需要帶傘,適合穿什麼衣服出門!