import requests
import json
def weather_report(city,low_temperature,highest_temperature,weather):
'''输出天气'''
output = '''
{0}今日天气
最低气温:{1}
最高气温:{2}
{3}
'''
print(output.format(city,low_temperature,highest_temperature,weather))
url = 'http://www.weather.com.cn/data/cityinfo/101010100.html'
response = requests.get(url)
response.encoding = "utf-8"
# 方式1:将JSON字符串转化为字典
weatherinfo = response.text # JSON类型数据
data = json.loads(weatherinfo) # 转化为字符串类型
info = data['weatherinfo']
weather_report(info['city'],info['temp1'],info['temp2'],info['weather'])
# 方式2:直接返回字典类型
weatherinfo = response.json()
info = weatherinfo['weatherinfo']
weather_report(info['city'],info['temp1'],info['temp2'],info['weather'])
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码Python 如何解析JSON字符串 Python源码
资源推荐
资源详情
资源评论
收起资源包目录
13 如何解析JSON字符串.zip (1个子文件)
13 如何解析JSON字符串
run.py 886B
共 1 条
- 1
资源评论
douluo998
- 粉丝: 1845
- 资源: 5197
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功