Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic stefanpejcic/movies.py
Last active Aug 29, 2019

Embed
What would you like to do?
IMDB rating for movies in cinema with python
# -*- coding: UTF-8 -*-
from splinter import Browser
import sys
executable_path = {'executable_path':'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'}
#browser = Browser('chrome', **executable_path)
movie_titles = []
movie_ratings = []
with Browser('chrome', **executable_path) as cinema_browser:
url = "http://www.cinemaone.ro/movies/"
cinema_browser.visit(url)
div = cinema_browser.find_by_xpath('//div[@class="title"]')
prev_title = 'null'
for link in div:
links = link.find_by_tag('a')
if prev_title != links.first.value:
print (links.first.value)
movie_titles.append(links.first.value)
prev_title = links.first.value
with Browser('chrome', **executable_path) as imdb_browser:
url = "http://www.imdb.com/"
for title in movie_titles:
imdb_browser.visit(url)
imdb_browser.fill('q', title)
button = imdb_browser.find_by_id('navbar-submit-button')
button.click()
if imdb_browser.is_text_present('title'):
print("Yes, the official website was found for " + title)
h = imdb_browser.find_by_xpath('//td[@class="result_text"]')
link = h.find_by_tag('a')
link.first.click()
try:
rating = imdb_browser.find_by_xpath('//span[@itemprop="ratingValue"]').value
movie_ratings.append(rating)
except:
movie_ratings.append('N/A')
else:
print("No," + title + " wasn't found...")
count = 0
current = 0
def print_row(title, rating):
print(' %-45s %-15s ' % (title, rating))
print('\n\n\n')
print_row ('TITLE', 'RATING')
print_row ('-----', '------')
for data in movie_titles:
print_row(movie_titles[count], movie_ratings[count])
#print ((movie_titles[count] + ' \t\t\t ' + movie_ratings[count]))
count = count + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.