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

熱點內容
內置存儲卡可以拆嗎 發布:2025-05-18 04:16:35 瀏覽:335
編譯原理課時設置 發布:2025-05-18 04:13:28 瀏覽:378
linux中進入ip地址伺服器 發布:2025-05-18 04:11:21 瀏覽:612
java用什麼軟體寫 發布:2025-05-18 03:56:19 瀏覽:32
linux配置vim編譯c 發布:2025-05-18 03:55:07 瀏覽:107
砸百鬼腳本 發布:2025-05-18 03:53:34 瀏覽:943
安卓手機如何拍視頻和蘋果一樣 發布:2025-05-18 03:40:47 瀏覽:739
為什麼安卓手機連不上蘋果7熱點 發布:2025-05-18 03:40:13 瀏覽:803
網卡訪問 發布:2025-05-18 03:35:04 瀏覽:511
接收和發送伺服器地址 發布:2025-05-18 03:33:48 瀏覽:371