This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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