On 19/05/13 18:05, Peter Otten wrote:
The original Python 2 code: $ cat parse.py import urllib2 import json url = "http://*********/goldencasket" s = urllib2.urlopen(url).read() s = s.partition("latestResults_productResults")[2].lstrip(" =") s = s.partition(";")[0] data = json.loads(s) lotto = data["GoldLottoSaturday"] print lotto["drawDayDateNumber"] print map(int, lotto["primaryNumbers"]) print map(int, lotto["secondaryNumbers"]) $ python parse.py Sat 18/May/13, Draw 3321 [14, 31, 16, 25, 6, 3] [9, 35]
It turns out that urllib2 and 3 are both built into python so I didn't have to stress over the dependency error. However, I do have an error and I'm not completely certain that I understand how the code provided by Peter works. The following is the error message:
Traceback (most recent call last): File "/home/phil/Python/lotto.py", line 10, in <module> data = json.loads(s) File "/usr/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded -- Regards, Phil _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor