當前位置:首頁 » 編程語言 » 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℃

熱點內容
車載中控安卓機如何安裝u盤聽歌 發布:2025-08-26 16:36:04 瀏覽:38
解壓密碼漢字 發布:2025-08-26 16:34:56 瀏覽:717
文檔怎樣上傳 發布:2025-08-26 16:15:00 瀏覽:303
瘋狂python講義pdf 發布:2025-08-26 15:33:36 瀏覽:301
蘋果三代通透模式在安卓怎麼關 發布:2025-08-26 15:19:20 瀏覽:150
thinkphp緩存清除 發布:2025-08-26 15:18:15 瀏覽:825
linux的未來 發布:2025-08-26 15:14:17 瀏覽:226
龍之谷競技場腳本 發布:2025-08-26 15:06:09 瀏覽:186
根伺服器如何搭建 發布:2025-08-26 15:02:23 瀏覽:464
我的世界網易ec伺服器ip地址 發布:2025-08-26 15:00:36 瀏覽:150