Created
July 9, 2016 17:48
-
-
Save tomplex/775af19ae9f7e785ced65f014fe73cf5 to your computer and use it in GitHub Desktop.
Convert jquery response to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
def convert_to_json(url): | |
# get the response | |
r = requests.get(url) | |
# get the content of the response and decode from bytes to str in UTF-8 | |
response = r.content.decode() | |
# the response is a jquery object, so we need to strip off the extra jquery nonsense. | |
# the beginning of the json object is the '[' so... | |
while not response.startswith('['): | |
# while the first character isn't a [, remove it | |
response = response[1:] | |
# now remove the final parenthesis | |
response = response[:-1] | |
return json.loads(response) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment