import requests
url='http://www.weather.com.cn/data/sk/101010100.html'#将网址定义变量
r=requests.get(url)
r.encoding='utf8' #转码
data=r.json() #转码查看放在变量data里,变成一个字典了
print("城市:",data['weatherinfo']['city'])
print("温度:",data['weatherinfo']['temp'])
import requests
url='http://www.weather.com.cn/data/sk/101010100.html'#将网址定义变量
r=requests.get(url)
r.encoding='utf8' #转码
data=r.json() #转码查看放在变量data里,变成一个字典了
print("城市:",data['weatherinfo']['city'])
print("温度:",data['weatherinfo']['temp'])