Skip to content

Instantly share code, notes, and snippets.

@LegeBeker
Last active January 2, 2024 23:43
Show Gist options
  • Save LegeBeker/2b5a8e82b8c1ee3ebbb9865451dae910 to your computer and use it in GitHub Desktop.
Save LegeBeker/2b5a8e82b8c1ee3ebbb9865451dae910 to your computer and use it in GitHub Desktop.
Current Cineville films export for use in a Letterboxd list. https://letterboxd.com/volkaneur/list/films-in-cineville-cinemas/
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import datetime
options = webdriver.ChromeOptions()
options.add_argument('headless')
driver = webdriver.Chrome(options=options)
driver.get('https://www.cineville.nl/films')
# Wait for the cookie dialog to appear and accept it
try:
accept_cookies_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, 'CybotCookiebotDialogBodyButtonDecline'))
)
accept_cookies_button.click()
except Exception as e:
print(f"Error accepting cookies: {e}")
# Wait for the movies to load
try:
movies = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.CLASS_NAME, 'card__title'))
)
except Exception as e:
print(f"Error loading movies: {e}")
# Parse the HTML
html = driver.page_source
soup = BeautifulSoup(html, 'html.parser')
# Get the movie titles
movies = soup.find_all('h3', {'class': 'card__title'})
for movie in movies:
movie = movie.text.split('(')[0]
print(movie)
# make filename cineville-<date>
filename = 'cineville-' + str(datetime.date.today())
# write to file
with open('./' + filename + '.csv', 'w') as f:
f.write('Title\n')
for movie in movies:
movie = movie.text.split('(')[0]
f.write(movie + '\n')
# Close the browser
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment