-
Notifications
You must be signed in to change notification settings - Fork 0
/
getLinks.js
31 lines (27 loc) · 862 Bytes
/
getLinks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: false })
// go to the page
// gather all the links from top of the box office
const getLinks = nightmare
.goto('https://www.rottentomatoes.com')
.wait('body')
.evaluate(() => {
const gatherLinks = category =>
Array.from(
document
.getElementById(category)
.getElementsByClassName('sidebarInTheaterOpening')
).map(movie => movie.querySelector('a').href)
let openingThisWeek = gatherLinks('homepage-opening-this-week')
let topOfTheBoxOffice = gatherLinks('homepage-top-box-office')
return [
{ 'opening this week': openingThisWeek },
{ 'top of the box office': topOfTheBoxOffice }
]
})
.end()
.then(result => {
console.log(result)
})
.catch(err => console.error(err))
module.exports = getLinks