Last active
June 14, 2022 20:45
-
-
Save huchenme/0e9c03904279a166d6662e48d61d51c2 to your computer and use it in GitHub Desktop.
cheerio tutorial all titles
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
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