-
Notifications
You must be signed in to change notification settings - Fork 14
/
imdb.js
31 lines (27 loc) · 952 Bytes
/
imdb.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 { webkit } = require('playwright');
(async () => {
const browser = await webkit.launch();
const context = await browser.newContext();
const page = await context.newPage();
page.on('pageerror', console.log);
try {
await page.goto('https://www.imdb.com/chart/top/?sort=rk,asc&mode=simple', {
waitUntil: 'networkidle',
});
await page.waitForSelector('#main div.lister .lister-list');
const movies = await page.evaluate(() => {
let list = document.querySelectorAll('#main div.lister .lister-list tr');
return Array.from(list).map((link) => ({
name: link.querySelector('.titleColumn a').innerHTML.trim(),
poster: link.querySelector('.posterColumn img').src,
rating: Number(
link.querySelector('.imdbRating strong').innerHTML.trim(),
),
}));
});
console.table(movies);
} catch (error) {
console.log(error);
}
await browser.close();
})();