A British find-a-movie challenge This is a more difficult version of  It&#39;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))
NodeJS

I'm an awful golfer tho

The inputs must be passed like this node filename 12,12A,15,18 4 for fetching a movie with one of the ratings comma separated and at least 4 stars

var fetch=require('node-fetch');
var {JSDOM, VirtualConsole}=require('jsdom');

var f=x=&gt;fetch(x).then(r=&gt;r.text());
var vc = new VirtualConsole(); // ignore annoying css errors
var [bbfc='U,PG,12',stars='3']=process.argv.slice(2);

var Z=async()=&gt;{
    for(var i=0;i&lt;10;i++){ // 10 max pages, can be anything
        var t= await f(`https://www.theguardian.com/film+tone/reviews?page=${i}`);
        var w=new JSDOM(t, {virtualConsole:vc}).window;
        for(var h of w.document.querySelectorAll('.fc-item__header')){
            if (h.querySelectorAll('.star__item--golden').length&gt;=stars){
                var title=h.querySelector('.js-headline-text').textContent.split(' review')[0].trim();
                var t=await f('http://www.bbfc.co.uk/search/releases/'+title);
                var rating=t.match(/BBF\w_(\w+)_/)[1];
                if(bbfc.includes(rating)) return title;
            }
        }
    }
};

Z()
.then(console.log)
.catch(console.error)