Created
March 18, 2023 10:58
-
-
Save szkrd/67259d1a885470ee8eacb6db387b8627 to your computer and use it in GitHub Desktop.
the proper amount of daily news
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
#!/usr/bin/env -S node --no-warnings | |
const { JSDOM } = require("jsdom"); | |
const ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0'; | |
function listHeadlines(url, title, selector) { | |
return fetch(url, { headers: { "User-Agent": ua}}).then((res) => res.text()).then((text) => { | |
const doc = (new JSDOM(text)).window.document; | |
const titles = Array.from(doc.querySelectorAll(selector)).map(el => el.textContent.trim()); | |
console.log(`====== [${title}] ======`); | |
titles.forEach((text) => console.log(`* ${text}`)); | |
}); | |
} | |
listHeadlines('https://www.reuters.com/news/archive/worldNews', 'Reuters', 'h3.story-title'); | |
listHeadlines('https://hvg.hu/', 'HVG', '.h500.articlebox h1.heading-3'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment