Skip to main content
Updated to find the exact movie
Source Link
JeffC
  • 26.4k
  • 5
  • 35
  • 57

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']Fire', 'The Matrix']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    ratinga = wait.until(EC.visibility_of_element_located((By.CSS_SELECTORXPATH, "divf"//a[.releases//h2[starts-with(text(), span"'{title} (')]]")))
    rating = a.find_element(By.CSS_SELECTOR, "span").get_attribute("aria-label").split("-")[1].upper()
    actual_title = wait.until(ECa.visibility_of_element_located(find_element(By.CSS_SELECTOR, "div.releases h2"))"h2").text
    print(f"{actual_title}: {rating}")

and it outputs

Toy Story 4 (2019): U
How To Train Your Dragon (2025): PG
Predator: Badlands (2024): 12A
Harry Potter And The Goblet Of Fire (2005): 12
The Matrix (1999): 15

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    rating = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases span"))).get_attribute("aria-label").split("-")[1].upper()
    actual_title = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases h2"))).text
    print(f"{actual_title}: {rating}")

and it outputs

Toy Story 4 (2019): U
How To Train Your Dragon (2025): PG
Predator: Badlands (2024): 12A
Harry Potter And The Goblet Of Fire (2005): 12

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire', 'The Matrix']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    a = wait.until(EC.visibility_of_element_located((By.XPATH, f"//a[.//h2[starts-with(text(), '{title} (')]]")))
    rating = a.find_element(By.CSS_SELECTOR, "span").get_attribute("aria-label").split("-")[1].upper()
    actual_title = a.find_element(By.CSS_SELECTOR, "h2").text
    print(f"{actual_title}: {rating}")

and it outputs

Toy Story 4 (2019): U
How To Train Your Dragon (2025): PG
Predator: Badlands (2024): 12A
Harry Potter And The Goblet Of Fire (2005): 12
The Matrix (1999): 15
Added actual title and release year
Source Link
JeffC
  • 26.4k
  • 5
  • 35
  • 57

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    rating = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases span"))).get_attribute("aria-label").split("-")[1].upper()
    actual_title = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases h2"))).text
    print(f"{titleactual_title}: {rating}")

and it outputs

Toy Story 4 (2019): U
How To Train Your Dragon (2025): PG
Predator: Badlands (2024): 12A
Harry Potter And The Goblet Of Fire (2005): 12

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    rating = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases span"))).get_attribute("aria-label").split("-")[1].upper()
    print(f"{title}: {rating}")

and it outputs

Toy Story 4: U
How To Train Your Dragon: PG
Predator: Badlands: 12A
Harry Potter And The Goblet Of Fire: 12

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    rating = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases span"))).get_attribute("aria-label").split("-")[1].upper()
    actual_title = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases h2"))).text
    print(f"{actual_title}: {rating}")

and it outputs

Toy Story 4 (2019): U
How To Train Your Dragon (2025): PG
Predator: Badlands (2024): 12A
Harry Potter And The Goblet Of Fire (2005): 12
Source Link
JeffC
  • 26.4k
  • 5
  • 35
  • 57

Here's a much simpler way to do this. You can fancy it up however you like but this is the guts of a really simple and fast way to get the ratings.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)

titles = ['Toy Story 4', 'How To Train Your Dragon', 'Predator: Badlands', 'Harry Potter And The Goblet Of Fire']
for title in titles:
    url = f'https://www.bbfc.co.uk/search?q={title}'
    driver.get(url)

    rating = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.releases span"))).get_attribute("aria-label").split("-")[1].upper()
    print(f"{title}: {rating}")

and it outputs

Toy Story 4: U
How To Train Your Dragon: PG
Predator: Badlands: 12A
Harry Potter And The Goblet Of Fire: 12