Skip to content

Instantly share code, notes, and snippets.

@szkrd
Created March 18, 2023 10:58
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 szkrd/67259d1a885470ee8eacb6db387b8627 to your computer and use it in GitHub Desktop.
Save szkrd/67259d1a885470ee8eacb6db387b8627 to your computer and use it in GitHub Desktop.
the proper amount of daily news
#!/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