“最美天氣”Python抓取天氣

jopen 8年前發布 | 22K 次閱讀 Python開發

import urllib.request
import urllib.parse
import json

"""     利用“最美天氣”抓取即時天氣情況     http://www.zuimeitianqi.com/

"""

class ZuiMei():     def init(self):         self.url = '

        html = response.read().decode('utf-8')         # 解析json數據并打印結果         self.json_parse(html)       def json_parse(self,html):         target = json.loads(html)         high_temp = target['data'][0]['actual']['high']         low_temp = target['data'][0]['actual']['low']         current_temp = target['data'][0]['actual']['tmp']         today_wea = target['data'][0]['actual']['wea']         air_desc = target['data'][0]['actual']['desc']         # 上海 6~-2°C 現在溫度 1°C 濕度:53 空氣質量不好,注意防霾。          print('%s: %s~%s°C 現在溫度 %s°C 濕度:%s %s'%(self.city,high_temp,low_temp,current_temp,today_wea,air_desc))

      

if name == 'main':     zuimei = ZuiMei()     zuimei.query('廣州')</pre>


來自: http://my.oschina.net/upy/blog/604341

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!