API requests
Now it's your turn to pull some movie data down from the Open Movie Database (OMDB) using their API.
The movie you'll query the API about is The Social Network.
Recall that, in the video, to query the API about the movie Hackers, Hugo's query string had a single argument t=hackers.
This exercise is part of the course
Importing Data in Python
Exercise instructions
- Import the
requestspackage. - Assign to the variable
urlthe URL of interest in order to query'http://www.omdbapi.com'for the data corresponding to the movie The Social Netork. The query string should have one argumentt=social+network. - Print the text of the reponse object
rby using itstextattribute and passing the result to theprint()function.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import requests package
# Assign URL to variable: url
# Package the request, send the request and catch the response: r
r = requests.get(url)
# Print the text of the response