# 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
最新推荐文章于 2024-10-08 20:27:53 发布