Created
April 21, 2024 23:42
-
-
Save cnleo/ca66da0dc7d1d1a957e9680ee3420f14 to your computer and use it in GitHub Desktop.
fetch_me_if_you_can.js
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
/** | |
* Node | |
* npm i jsdom | |
* 21+ dependencies | |
*/ | |
const jsdom = require("jsdom"); | |
const { JSDOM } = jsdom; | |
const url = 'https://heise.de'; | |
/** | |
* Deno | |
*/ | |
//import { DOMParser } from "https://deno.land/x/deno_dom/deno-dom-wasm.ts"; | |
async function fetchMeIfYouCan() { | |
const response = await fetch(url); | |
const responseText = await response.text(); | |
/** | |
* Node - jsdom | |
*/ | |
const parser = new JSDOM(responseText); | |
const htmlDocument = parser.window.document; | |
/** | |
* Browser and Deno - DOMParser | |
*/ | |
//const parser = new DOMParser(); | |
//const htmlDocument = parser.parseFromString(responseText, "text/html"); | |
const h2 = htmlDocument.querySelectorAll('h2'); | |
h2.forEach(element => { | |
console.log(element.textContent); | |
}); | |
} | |
fetchMeIfYouCan(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment