Posted By

spilcm on 01/13/13


Tagged

command line scraper IMDB


Versions (?)

Command Line IMDB Scraper


 / Published in: Python
 

URL: http://www.pythonforbeginners.com/scripts/imdb-crawler/

This script will ask for a movie title and a year and then query IMDB for it.

  1. #!/usr/bin/env python27
  2.  
  3. #Importing the modules
  4. from BeautifulSoup import BeautifulSoup
  5. import sys
  6. import urllib2
  7. import re
  8. import json
  9.  
  10. #Ask for movie title
  11. title = raw_input("Please enter a movie title: ")
  12.  
  13. #Ask for which year
  14. year = raw_input("which year? ")
  15.  
  16. #Search for spaces in the title string
  17. raw_string = re.compile(r' ')
  18.  
  19. #Replace spaces with a plus sign
  20. searchstring = raw_string.sub('+', title)
  21.  
  22. #Prints the search string
  23. print searchstring
  24.  
  25. #The actual query
  26. url = "http://www.imdbapi.com/?t=" + searchstring + "&y="+year
  27. request = urllib2.Request(url)
  28. response = json.load(urllib2.urlopen(request))
  29. print json.dumps(response,indent=2)

Report this snippet  

You need to login to post a comment.