Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created December 9, 2017 10:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save conanak99/0083a5188d1c6081da0cba71cfcd676d to your computer and use it in GitHub Desktop.
Save conanak99/0083a5188d1c6081da0cba71cfcd676d to your computer and use it in GitHub Desktop.
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