python - Parse Json String from HTTP response -
python - Parse Json String from HTTP response -
i trying parse json response http request in python. getting next exception:
valueerror: no json object decoded
python code:
profile = webdriver.firefoxprofile() profile.set_preference('network.http.phishy-userpass-length', 255) browser = webdriver.firefox(firefox_profile=profile) browser.get("https://"+username+":"+password+"@"+url) htmltext= str(browser.page_source) html=soup(htmltext) jsondata= str(html.find('pre')).strip('</pre>') data=json.loads(jsondata) print data['entries']
json response:
{ "count":1, "entries": [ { "id":15862, "application":loginaudit, "user":charan.kumar@speridian.com, "time":"2014-10-30t02:08:14.103-04:00", "values": { "\/loginaudit\/login\/no-error\/user":"charan.kumar@speridian.com" } } ] }
i see several problems here, 2 stand out are:
you using beautifulsoup parse page. if receiving json-like text posted, beautifulsoup not going able parse it. if did not throw error, output going form of html, not json.
the page show isn't valid json. values application
, user
not quoted @ all.
i'm puzzled why utilize selenium response. unless there javascript beingness executed on specific page (for can indeed utilize real browser have executed), seems using bulldozer seek , crack nut.
using standard library tools (urllib2
or urllib.request
, depending on python version) should suffice, perhaps few explicit http headers beingness set. personally, i'd utilize requests
module tasks these; comes built-in json handling.
python json
Comments
Post a Comment