This is a more difficult version of It's a find-a-movie challenge .
Input
Your code should take a BBFC rating and a number from 1 to 5 as input. It can do this in any way you find convenient.
Output
Your code should return the name of any movie which has a) that film rating and b) that number of stars in a Guardian film review.
If there is no such movie it can output anything you like.
The possible BBFC film ratings are U, PG, 12, 12A, 15, 18, R18, TBC
.
Your code may report one or more movies, that is up to you.
To clarify, your code is meant to access the web to get the answers to queries.
Example
Say the input is U, 5
then your code could output "My Neighbour Totoro".
Please show an example of your code working with the film rating PG
and score 4
along with your answer.
Notes
The Guardian does have an API but this requires registration. For this challenge you may not use it.
Example code
The following Python 3 code gets all the movies along with their score out of 5, although not 100% perfectly.
from bs4 import BeautifulSoup
import requests
import sys
for i in range(1,837):
print("Page", i,file=sys.stderr)
result = requests.get("https://www.theguardian.com/film+tone/reviews?page={0}".format(i))
data = result.text
soup = BeautifulSoup(data, "lxml")
tags = soup.find_all("div", {"class":"stars"})
for tag in tags:
stars = 0
for star in tag.find_all("span", {"class":"star__item--grey"}):
stars +=1
main = tag.parent
title = main.find("h2")
if title:
a = title.find("span", {"class":"js-headline-text"})
print("{} - {}".format(5 - stars, a.text))