Skip to content

Instantly share code, notes, and snippets.

@huchenme
Last active June 14, 2022 20:45
Show Gist options
  • Save huchenme/0e9c03904279a166d6662e48d61d51c2 to your computer and use it in GitHub Desktop.
Save huchenme/0e9c03904279a166d6662e48d61d51c2 to your computer and use it in GitHub Desktop.
cheerio tutorial all titles
import cheerio from 'cheerio';
import fetch from 'node-fetch';
const data = await fetch('https://github.com/trending');
const $ = cheerio.load(await data.text());
const allTitles = $('.repo-list li')
.get()
.map(repo => {
const $repo = $(repo);
const title = $repo.find('h3').text();
return title;
});
console.log(allTitles);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment