热搜词: 

python爬取天气详细代码

发布:蚁仲河

本文目录一览

python怎么打开gfs气象数据参考
http://www.jb51.net/post/48299.htm 求助:用python获取天气预报#获取温度、湿度、风力等
WEATHER_URL_A="http://www.weather.com.cn/data/sk/%s.html"
#获取天气状况、最高/小气温等
WEATHER_URL_B="http://www.weather.com.cn/data/cityinfo/%s.html"
#获取下次天气数据7天
URL中的%s是指城市对应的代码。 详细参考:
http://www.cnblogs.com/toosuo/p/3868004.html
但是本文中的一些接口已经不再可用。
上面我提供的三个URL中,前两个直接返回json格式数据,第三个返回一个页面,需要从页面中提取出想要的信息。

用python编写的获取天气预报的代码总是有错误,求解

weatherinfo=r.json()#在json后面添加括号返回输出。 否则只能返回地址函数。
ApiUrl="http://www.weather.com

以下:

导入请求
ApiUrl="http://www.weather.com。 cn/adat/cityinfo/101010100.html"
r=requests.get(ApiUrl)
weatherinfo=r.json()
print(weatherinfo["weatherinfo"]["ptime"])
print(weatherinfo["weatherinfo"]["temp2"]
>>08:00

>>5℃

以上就是关于python爬取天气详细代码的全部内容,希望能够帮到您。

大家都在看

查看更多综合百科