-
Notifications
You must be signed in to change notification settings - Fork 0
/
getprodinfo.js
60 lines (44 loc) · 1.68 KB
/
getprodinfo.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
const puppeteer = require('puppeteer');
const xlsx = require('xlsx');
async function getDataFromPage(url, page) {
await page.goto(url);
await page.waitFor(3000);
const title = await page.$eval('.lcol h1', h1 => h1.textContent);
const description = await page.$eval('.dept-ct.show-less p', description => description.textContent);
const tags = await page.$eval('.single-tags a', tags => tags.textContent);
const links = await page.$eval('.srv.default-srv', links => links.getAttribute('data'));
return {
title: title,
description: description,
link_url: links,
tags: tags
}
};
async function getLinkFromMainWeb() {
// Mở trình duyệt mới và tới trang của kenh14
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto('https://phimporn.com/');
const links = await page.$$eval('.post .m .post-title a', allAs => allAs.map(a => a.href));
await browser.close();
return links;
};
async function main() {
const alllinks = await getLinkFromMainWeb();
// Mở trình duyệt mới và tới trang của kenh14
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
const scrapedData = [];
for (let link of alllinks) {
const data = await getDataFromPage(link, page);
//await page.waitFor(3000);
scrapedData.push(data);
}
//console.log(scrapedData);
const wb = xlsx.utils.book_new();
const ws = xlsx.utils.json_to_sheet(scrapedData);
xlsx.utils.book_append_sheet(wb,ws);
xlsx.writeFile(wb,"test.xlsx");
await browser.close();
}
main();