Python3 處理JSON的實例詳解
更新時間:2017年10月29日 08:36:37 作者:dove1980
這篇文章主要介紹了Python3 處理JSON的實例詳解的相關資料,希望通過本文能幫助到大家,讓大家實現這樣的功能,需要的朋友可以參考下
Python3 處理JSON的實例詳解
真的好簡單,灰常簡單
import os, io, sys, re, time, base64, json import webbrowser, urllib.request def main(): "main function" url = "http://m.weather.com.cn/data/101010100.html" stdout=urllib.request.urlopen(url) weatherInfo= stdout.read().decode('utf-8') #print(weatherInfo) jsonData = json.loads(weatherInfo)
輸出JSON數據
szCity = jsonData["weatherinfo"]["city"] print("城市: ", szCity) szTemp = jsonData["weatherinfo"]["temp1"] print("溫度: ", szTemp) szWeather1 = jsonData["weatherinfo"]["weather1"] print("天氣情況: ",szWeather1) szCityid = jsonData["weatherinfo"]["cityid"] print("城市編碼: ",szCityid) if __name__ == '__main__': main()
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
Mac中Python 3環(huán)境下安裝scrapy的方法教程
作為一名python爬蟲愛好者,怎能不折騰下Scrapy?折騰了許久之后終于安裝到了mac中,所以下面這篇文章主要給大家介紹了關于Mac系統中Python 3環(huán)境下安裝scrapy的相關資料,文中將實現的步驟一步步介紹的非常詳細,需要的朋友可以參考下。2017-10-10python庫patchworklib多圖表整合用法示例探究
這篇文章主要介紹了python庫patchworklib對齊matplotlib圖表,將多個圖表的整合為單一圖表用法示例探究,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2024-01-01