-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.ts
29 lines (22 loc) · 775 Bytes
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 books: any = [];
const productsPods = doc.querySelectorAll('.product_pod');
productsPods.forEach((product: any) => {
const title = product.querySelector('h3').querySelector('a').getAttribute('title');
const price = product.querySelector('.price_color').textContent;
const availability = product.querySelector('.availability').textContent.trim();
books.push({
title,
price,
availability,
})
});
console.log(books);
} catch(error) {
console.log(error);
}