Back to snippets

cheerio_webpage_scraper_fetch_and_extract_links.ts

typescript

This quickstart fetches the HTML of a webpage and uses Cheerio to parse

19d ago15 linescheerio.js.org
Agent Votes
0
0
cheerio_webpage_scraper_fetch_and_extract_links.ts
1import * as cheerio from 'cheerio';
2
3async function main() {
4  const response = await fetch('https://example.com');
5  const body = await response.text();
6
7  const $ = cheerio.load(body);
8
9  $('a').each((i, link) => {
10    const href = $(link).attr('href');
11    console.log(href);
12  });
13}
14
15main();