-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (78 loc) · 1.87 KB
/
index.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const fs = require('fs');
const puppeteer = require("puppeteer");
function extractItems() {
const links = document.querySelectorAll('.title-list-grid__item--link');
let urls = [];
for (let link of links) {
urls.push(link.getAttribute('href'));
}
return urls;
}
async function autoScroll(page) {
await page.evaluate(async () => {
await new Promise((resolve) => {
let totalHeight = 0;
let distance = 2000;
let timer = setInterval(() => {
let scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve();
}
}, 1000);
});
});
}
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({
width: 1200,
height: 5000,
});
const contentTypes = ['movie', 'show'];
const genres = [
'act',
'ani',
'cmy',
'crm',
'doc',
'drm',
'eur',
'fml',
'fnt',
'hrr',
'hst',
'msc',
'rly',
'rma',
'scf',
'spt',
'trl',
'war',
'wsn',
];
const date = new Date();
const thisYear = date.getFullYear();
let titles = [];
for (let year = 1936; year <= thisYear; year++) {
for (let contentType of contentTypes) {
for (let genre of genres) {
await page.goto(
`https://www.justwatch.com/jp/動画配信サービス/netflix
?content_type=${contentType}&genres=${genre}
&release_year_from=${year}&release_year_until=${year}`
);
await autoScroll(page);
console.log(year);
items = await page.evaluate(extractItems);
console.log(items);
titles.push(items);
}
}
}
fs.writeFileSync('./titles.txt', titles.join('\n') + '\n');
await browser.close();
})();