-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (26 loc) · 1.01 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
const puppeteer = require('puppeteer');
(async() => {
// 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/');
// Chạy đoạn JavaScript trong hàm này, đưa kết quả vào biến article
const articles = await page.evaluate(() => {
var links = document.querySelectorAll('.post-title a');
links = [...links];
let articles = links.map(link => ({
title: link.getAttribute('title'),
url: link.getAttribute('href')
}));
return articles;
});
// In ra kết quả và đóng trình duyệt
console.log(articles);
articles.forEach(element => {
console.log(element.url);
const browser2 = await puppeteer.launch({ headless: false });
const page2 = await browser2.newPage();
await page2.goto(element.url);
});
await browser.close();
})();