Recently in the weather business delayed monitoring, is every one hours to check the weather data is changed, 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 get the field we want is the first consideration of the issue.
In general, when we take down data from a Web page, it's a string, like:
Copy Code code as follows:
Url_data = Urllib2.urlopen (URL). ReadLine ()
When we get the page data like this, Url_data is the entire page displaying a JSON string, then how do we convert this string into a dictionary format: time = Json.loads (Url_data) ["Weatherinfo"] ["Time"]
The function loads () of the JSON module allows you to encode 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 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