Skip to content

Instantly share code, notes, and snippets.

@siddacool
Created November 4, 2020 14:38
Show Gist options
  • Save siddacool/1ae8ac6542de05bddc14a0951fabd266 to your computer and use it in GitHub Desktop.
Save siddacool/1ae8ac6542de05bddc14a0951fabd266 to your computer and use it in GitHub Desktop.
deno-web-scraper: Step 02
import { DOMParser } from 'https://deno.land/x/deno_dom/deno-dom-wasm.ts';
const url = 'http://books.toscrape.com/';
try {
const res = await fetch(url);
const html = await res.text();
const doc: any = new DOMParser().parseFromString(html, 'text/html');
const pageHeader = doc.querySelector('.header').querySelector('.h1').textContent;
console.log(pageHeader)
} catch(error) {
console.log(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment