Recently in the weather operation of the delay monitoring, is every one hours to check whether the weather data changes, three times do not change the alarm. Because the page gives the data in JSON format, so how to parse the data on the page, so that we want to get the field is the first thing we consider.
In general, when we take the data from a webpage, it is a string, such as:
Copy the Code code as follows:
Url_data = Urllib2.urlopen (URL). ReadLine ()
When we get the page data this way, Url_data is displaying a JSON string on all pages, so how do we turn this string into a dictionary format: time = Json.loads (Url_data) ["Weatherinfo"] ["Time"]
The function loads () of the JSON module encodes the original string into a dictionary, so that we can find the key value of a field much more convenient.
Some of the code is as follows:
Copy the Code code as follows:
def getTime (URL):
Url_data = Urllib2.urlopen (URL). ReadLine ()
Print Url_data
Time = Json.loads (Url_data) ["Weatherinfo"] ["Time"]
Return time