python爬蟲-經過api獲取所在城市的天氣

中國天氣網:html

http://www.weather.com.cn/data/sk/101020100.htmlpython

顏色處爲城市代碼,在輸入框中輸入對應城市,就能夠在html中看到對應的城市代碼json

import requests
r = requests.get('http://www.weather.com.cn/data/sk/101020100.html')
r.encoding = 'utf-8'
print r.json()['weatherinfo']['city'], r.json()['weatherinfo']['WD'], r.json()['weatherinfo']['temp']
相關文章
相關標籤/搜索