Python IMDB Movies website Scraper


SUBMITTED BY: alemotta

DATE: April 4, 2017, 1:04 p.m.

UPDATED: Dec. 8, 2017, 12:21 p.m.

FORMAT: Text only

SIZE: 723 Bytes

HITS: 814

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

comments powered by Disqus