Python 114la Weather Api

本文将讲解如何通过 114啦 的天气工具,获取城市的天气数据。
有用链接:获取114啦城市天气接口
英文原文:龙岩市天气接口

    import json
    import urllib2


    url = "http://weather.api.114la.com/2307/101230701.txt"

    content = urllib2.urlopen(url).read()
    print content.__class__
    # < type 'str' >

    print content.find('{')
    print content.rfind('}')
    # 23
    # 2345

    raw_data = content[content.find('{'):content.rfind('}')+1]

    json_data = json.loads(raw_data)
    print json_data.__class__
    # < type 'dict' >

    print  json_data.get('weatherinfo').get('city')
    print  json_data.get('weatherinfo').get('date_y')
    print  json_data.get('weatherinfo').get('temp1')
    print  json_data.get('weatherinfo').get('weather1')
    # 龙岩
    # 2014年5月28日
    # 24℃~32℃
    # 阵雨转阴

2014-05-28

rocket-wing