Rotten Tomatoes scraper for Node.js
npm install rotten-movies --save
The first step is finding the URL of the movie, this is where findUrl()
comes in.
var movieUrl = undefined
rottenMovies.findUrl('Up', '2009', undefined, function(err, url) {
if (err) {
console.log(err)
} else {
movieUrl = url
}
})
The url
argument is simply the URL that all Rotten Tomatoes movie pages follow, in most cases you can leave it as undefined
as it's hard coded in (as https://www.rottentomatoes.com/m/), but if Rotten Tomatoes changes this, you should manually fill it in.
The year
argument is also optional, but it's highly recommend to yield a more accurate result.
Once you have obtained the URL for the movie, you can begin obtaining information. To find the critic and audience rating, simply use scores()
.
rottenMovies.scores('https://www.rottentomatoes.com/m/up', function(err, scores) { ... })
The scores
variable is a dictionary with a critic
and audience
key.
{
critic: '98',
audience: '90'
}
You can also find out more information about the movie using info()
.
rottenMovies.info('https://www.rottentomatoes.com/m/up', function(err, info) { ... })
The info
variable is a dictionary with a name
and description
key.
{
name: 'Up (2009)',
description: 'A feisty septuagenarian teams with a fearless wilderness ranger to do battle with a vicious band of beasts and villains in this computer-animated adventure scripted by Pixar veteran Bob Peterson and co-directed by Peterson and Monsters, Inc. director Peter Docter.'
}