# Used to open url data import urllib2 # Used to handle and manipulate JSON import json def printResults(data): # Use the json module to load the string data into a dictionary theJSON = json.loads(data) # now we can access the contents of the JSON like any other Python object #if "description" in theJSON["data"]: # return "description" return theJSON def main(): # define var to hold source URL urlData = "http://imdb.wemakesites.net/api/tt2488496" # specifically Star Wars 7 # Open the URL and read the data webUrl = urllib2.urlopen(urlData) # Opens the URL to get data print webUrl.getcode() # prints result code, looking for ok / 200 if (webUrl.getcode() == 200): # if all ok, read data from URL, retrieve JSON data data = webUrl.read() # print out our customized results # printResults(data) # prints customized results json_encoded_data = json.dumps(data) return json_encoded_data # return data # RETURNS STRING NOT JSON else: print "Received an error from server, cannot retrieve results " + str(webUrl.getCode()) jsonData = main() print jsonData """ returns: "{\"status\":\"success\",\"code\":200,\"message\":\"ok\",\"data\":{\"id\":\"tt2488496\",\"type\":\"title\",\"title\":null,\"year\":null,\"description\":\"30 years after the defeat of Darth Vader and the Empire, Rey, a scavenger from the planet Jakku, finds a BB-8 droid that knows the whereabouts of the long lost Luke Skywalker. Rey, as well as a rogue stormtrooper and two smugglers, are thrown into the middle of a battle between the Resistance and the daunting legions of the First Order. Written byNoah White\",\"certificate\":\"\",\"duration\":\"2h 16min\",\"released\":\"2015-12-18\",\"cast\":[\"Harrison Ford\",\"Mark Hamill\",\"Carrie Fisher\",\"Adam Driver\",\"Daisy Ridley\",\"John Boyega\",\"Oscar Isaac\",\"Lupita Nyong'o\",\"Andy Serkis\",\"Domhnall Gleeson\",\"Anthony Daniels\",\"Max von Sydow\",\"Peter Mayhew\",\"Gwendoline Christie\",\"Joonas Suotamo\"],\"genres\":[\"action\",\"adventure\",\"fantasy\",\"sci-fi\"],\"directors\":[],\"writers\":[],\"image\":\"http:\\/\\/ia.media-imdb.com\\/images\\/M\\/MV5BOTAzODEzNDAzMl5BMl5BanBnXkFtZTgwMDU1MTgzNzE@._V1_UX182_CR0,0,182,268_AL_.jpg\",\"review\":{\"text\":\"Unoriginal plot, characters, planets, space fighters, weapons, script ........ This movie makes the prequels look stunningly good. You have already seen this movie before - in 1977! The original was enjoyable, this unfortunately is a predictable yawner. I actually fell asleep a various points because I knew that I wouldn't miss much.It's tragic that this reboot has been wasted when both Rey and Finn pull off relatively good performances even if we have seen their characters before.This is targeted at youth under 20. A re-introduction to Star Wars that will sadden and disappoint most die-hard fans.If your over 20 years of age save your money and go see something else.PS - Jurassic World suffers the same fate!\",\"rating\":\"2\\/10\"}}}" """
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question