-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetflix.js
43 lines (37 loc) · 1.25 KB
/
netflix.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
const puppeteer=require('puppeteer')
async function netflix(event,client,prefix) {
const message=event.message.text
if (message === prefix + "n") {
let browser;
browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const [page] = await browser.pages();
await page.goto("https://top10.netflix.com/taiwan/tv");
let dramas = [];
for (let i = 1; i <= 10; i++) {
const Netflix_path = `/html/body/div[1]/div/main/section[2]/div/div[5]/div/div[1]/div/table/tbody/tr[${i}]/td[2]`;
await page.waitForXPath(Netflix_path);
const n_result = await page.$x(Netflix_path);
const nao = await n_result[0].evaluate((x) => x.textContent);
console.log(nao);
dramas.push(nao);
function delay(time) {
return new Promise(function (resolve) {
setTimeout(resolve, time);
});
}
await delay(1000);
}
await browser.close();
return client.replyMessage(event.replyToken, {
type: "text",
text:
"Netflix週排行榜:" +
"\n" +
dramas.map((x, i) => `${i + 1}. ${x}`).join("\n"),
});
}
}
module.exports={netflix}