python 中的 requests
库,这是一个用来获取网络资源的模块。它是一个第三方库,所以需要安装:
$ python -m pip install requests
使用
import requests
req = requests.get('http://wthrcdn.etouch.cn/weather_mini?city=成都')
print(req)
req.encoding = 'utf8'
content = req.text
print(content)
dic_city = req.json() # 将 json 数据转换成字符串
city_data = dit_city['data']['forecast'][0]['type']