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']
相关文章
相关标签/搜索