zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    StarUML
    第二周周二日报
    第二周周一日报
    第一周周末报
    第一周周四日报
    第一周第三天日报
    软件开发总结
    构建之法总结
    《构建之法》第六章
    个人日志7
  • 原文地址:https://www.cnblogs.com/eaglezzb/p/4176520.html
Copyright © 2011-2022 走看看