Feeds:
Posts
Comments

Posts Tagged ‘movie’

Here is a script i wrote last night.It finds imdb rating of a movie.

#ragsagar[at]gmail.com
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import sys,re

if len(sys.argv) != 2:
	print "\nSyntax: python %s 'Movie title'" % (sys.argv[0])
	exit()
else :
	movie = '+'.join(sys.argv[1].split())

br = Browser()
br.open("http://www.imdb.com/find?s=tt&q="+movie)
link = br.find_link(url_regex = re.compile(r"/title/tt*"))
res = br.follow_link(link)
soup = BeautifulSoup(res.read())
try :
	title = soup.find('h1').contents[0].strip()
	rating = soup.find('span',attrs='rating-rating').contents[0]
	print "Movie : ",title
	print "Rating: ",rating,"/ 10.0"
except :
	print "Not Found!"	

Here is the screenshot of output.

Output of the script

Read Full Post »