```
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”])