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