# coding=utf-8
import urllib,json
def getCityWeather(cityId):
url="http://www.weather.com.cn/data/sk/"+str(cityId)+".html"
stdout=urllib.urlopen(url)
weatherInfo=stdout.read().decode("utf-8")
jsonData=json.loads(weatherInfo,encoding="utf-8")
city=jsonData["weatherinfo"]["city"]
temp=jsonData["weatherinfo"]["temp"]
print city,temp
if __name__=="__main__":
getCityWeather(101040100)
Python urllib
最新推荐文章于 2025-12-22 13:59:14 发布
本文介绍了一个简单的Python脚本,该脚本使用urllib和json模块从特定URL获取城市天气信息。通过传递城市ID作为参数,可以获取对应城市的温度等气象数据。
1156

被折叠的 条评论
为什么被折叠?



