#open() #urlopen() #方法名称不同 #参数不同 #只能以只读模式打开网络资源文件 from urllib.request import urlopen from urllib.parse import quote from json import loads from time import time,sleep print(‘请输入要查询的城市名称:‘) s=input() s1=quote(s) #print(s1) url=‘http://www.sojson.com/open/api/weather/json.shtml?city=‘+s1 f=urlopen(url) #read() #readline() #readlines() result=f.read().decode() result=loads(result) #a=a+1 day1=result[‘data‘][‘forecast‘][0] print(‘日期:‘,day1[‘date‘]) print(‘天气状态:‘,day1[‘type‘]) print(‘风向:‘,day1[‘fx‘]) print(‘今天最低温度:‘,day1[‘low‘]) print(‘今天最高温度:‘,day1[‘high‘]) print(‘注意事项:‘,day1[‘notice‘]) f.close()
原文地址:https://www.cnblogs.com/minkillmax/p/8313133.html
时间: 2024-10-13 23:50:06