python小程序查询天气状态

在这里插入图片描述```
import requests
from random import choice
import json
list_u=[‘Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920)’,
‘Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; SAMSUNG; SGH-i917)’,
‘Mozilla/4.0 (compatible; MSIE 7.0; Windows Phone OS 7.0; Trident/3.1; IEMobile/7.0; LG; GW910)’,
’ Mozilla/5.0 (Windows NT 6.2; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0’,
’ Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20130331 Firefox/21.0’,
’ Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:21.0) Gecko/20100101 Firefox/21.0’,
‘Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0’]
data={“User-Agent”:choice(list_u)}#随机产生请求头

cityname=input(‘请输入你要查询的城市:’)

cityname=“成都”

response=requests.get(“http://toy1.weather.com.cn/search?cityname=”+cityname)
code=(response.text[10:19])
response=requests.get(“http://t.weather.sojson.com/api/weather/city/”+code)
txt=json.loads(response.text.encode(“utf-8”))
content=(txt[“data”])
jianyi=(content[“ganmao”])
new=(content[“forecast”][0])
print(“城市:”+cityname)
print(“温馨提示:”+jianyi)
print(“日期:”+new[“ymd”]+"\t\t"+new[‘week’])
print(“日出时间:”+new[“sunrise”]+"\t\t"+“日落时间:”+new[“sunset”])
print(“最高温度:”+new[“high”]+"\t"+“最低温度:”+new[“low”]+"\t"+new[“fx”]+new[“fl”]+"\t\t"+new[“type”])


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值