Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created December 9, 2017 10:57
Embed
What would you like to do?
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('http://kenh14.vn');
// Chạy đoạn JavaScript trong hàm này, đưa kết quả vào biến article
const articles = await page.evaluate(() => {
let titleLinks = document.querySelectorAll('h3.knswli-title > a');
titleLinks = [...titleLinks];
let articles = titleLinks.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);
await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment