Skip to main content
  1. Posts/

Letterboxd Watchlist Picker

This script was made for educational purposes only. Web-scraping is against the Letterboxd TOS.

Goal

Write a Python script that chooses a random movie from a user’s Letterboxd watchlist.

Getting Started

Start by importing the necessary Python libraries for scraping a webpage and then choosing a random selection from an array.

import requests
from bs4 import BeautifulSoup
import random

Configuring BeaufifulSoup

Next we will define our variables and tell the BeautifulSoup library how to find the film title when scraping the web page.

# Set the URL of the user's Letterboxd watchlist
url = "https://letterboxd.com/mackiser/watchlist/"

# Make a GET request to the URL
response = requests.get(url)

# Parse the HTML content of the page
soup = BeautifulSoup(response.content, "html.parser")

# Find all the movie elements on the page
movies = soup.find_all("div", class_="film-poster")

Selecting a Random Film

Now we will use the random library to choose a random film from the array of movies we have now.

# Pick a random movie from the list
random_movie = random.choice(movies)
print(title)

Output

$ python3 watchlistPicker.py
Citizen Kane