当前位置:首页 » 编程语言 » 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℃

热点内容
scratch少儿编程课程 发布:2025-04-16 17:11:44 浏览:637
荣耀x10从哪里设置密码 发布:2025-04-16 17:11:43 浏览:366
java从入门到精通视频 发布:2025-04-16 17:11:43 浏览:82
php微信接口教程 发布:2025-04-16 17:07:30 浏览:307
android实现阴影 发布:2025-04-16 16:50:08 浏览:789
粉笔直播课缓存 发布:2025-04-16 16:31:21 浏览:339
机顶盒都有什么配置 发布:2025-04-16 16:24:37 浏览:210
编写手游反编译都需要学习什么 发布:2025-04-16 16:19:36 浏览:810
proteus编译文件位置 发布:2025-04-16 16:18:44 浏览:364
土压缩的本质 发布:2025-04-16 16:13:21 浏览:590