当前位置:首页 » 编程语言 » python天气数据

python天气数据

发布时间: 2024-07-29 17:17:35

㈠ 求助:用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天天气数据
WEATHER_URL_C = "http://www.weather.com.cn/weather/%s.shtml"

URL里%s指城市对应的代码。详细参考:
http://www.cnblogs.com/toosuo/p/3868004.html
不过这篇文章里有的接口已经不能用了。
上面我给的三个URL里,前两个直接返回json格式数据;第三个返回是一个页面,需要自己从页面里提取想要的信息。

㈡ python如何保存网页天气预报并保存为csv

你可以通过爬虫技术将数据全部爬取下来,然后存放在DataFrame中,最后用.to_csv来保存

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

weatherinfo=r.json() #在json后面加上括号才能返回结果。否则只能返回函数地址。

以下python3通过:

importrequests
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℃

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:710
制作脚本网站 发布:2025-10-20 08:17:34 浏览:972
python中的init方法 发布:2025-10-20 08:17:33 浏览:681
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:833
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:741
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1081
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:312
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:192
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:880
python股票数据获取 发布:2025-10-20 07:39:44 浏览:837