python 中的 requests 库,这是一个用来获取网络资源的模块。它是一个第三方库,所以需要安装:

  1. $ python -m pip install requests

使用

  1. import requests
  2. req = requests.get('http://wthrcdn.etouch.cn/weather_mini?city=成都')
  3. print(req)
  4. req.encoding = 'utf8'
  5. content = req.text
  6. print(content)
  7. dic_city = req.json() # 将 json 数据转换成字符串
  8. city_data = dit_city['data']['forecast'][0]['type']