There is nothing to do to get the weather API, roughly checked, the domestic relatively good or Chinese weather Network (China Meteorological station), the portal has Sina and Tencent (search), other some small sites worry about instability, so no use.
The simplest script. Send a request to get JSON and parse it and simply output it to the screen.
This is only used in the Beijing area, and other areas need to replace the relevant code in the URL address. The code can be found in the reference link below.
Screenshot below, and there are garbled, no way, python garbled too disgusting, in the idle run is normal, do it:
Reference Links:
Http://www.weste.net/2012/8-23/84850.html
#! /usr/bin/python # coding = utf-8 # Todo:get weather info from weather.com.cn # author:steven # DATE:2013/05/13 Import URLLIB2 Import JSON # get weather HTML and parse to JSON weatherhtml = Urllib2.urlopen (' http://m.weather.com.cn/data/101 010100.html '). Read () Weatherjson = json. Jsondecoder (). Decode (weatherhtml) weatherinfo = weatherjson[' Weatherinfo '] # print weather info print ' City: \ t ', Weatherin fo[' city '] print ' time: \ t ', weatherinfo[' date_y '] print ' 24-hour weather: ' print ' temperature: \ t ', weatherinfo[' Temp1 '] print ' weather: \ t ', weathe rinfo[' weather1 '] print ' wind speed: \ t ', weatherinfo[' wind1 '] print ' ultraviolet: \ t ', weatherinfo[' index_uv '] print ' clothing index: \ t ', weatherinfo[' index_d '] print ' 48-hour weather: ' print ' temperature: \ t ', weatherinfo[' temp2 '] print ' weather: \ t ', weatherinfo[' weather2 '] Print
' Wind speed: \ t ', weatherinfo[' wind2 '] print ' UV: \ t ', weatherinfo[' index48_uv '] print ' dressing index: \ t ', weatherinfo[' index48_d ' print ' 72-hour weather: ' print ' temperature: \ t ', weatherinfo[' Temp3 '] print ' weather: \ t ', weatherinfo[' Weather3 '] print ' wind speed: \ t ', weatherinfo[' Wind3 ']