Skip to content

Instantly share code, notes, and snippets.

@stefanpejcic
Last active August 29, 2019 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanpejcic/0bc219fc1853831bf428a8be5c951a16 to your computer and use it in GitHub Desktop.
Save stefanpejcic/0bc219fc1853831bf428a8be5c951a16 to your computer and use it in GitHub Desktop.
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