Today I Learned - Rocky Kev

TIL a quick recipe involving Axios and Cheerio

POSTED ON:

TAGS:

Axios is a more feature-rich fetch.

It's also great because Fetch has limited support (back in the day. It has better support now).

Cheerio is a library to web scrape.

It allows you to visit a site, download it in pure html fashion, then traverse the content and only pull the data you need.

Using Axios

const axios = require("axios")
const cheerio = require("cheerio");

const getBreeds = async () => {
try {
return await axios.get("https://dog.ceo/api/breeds/list/all")
} catch (error) {
console.error(error)
}
}

const countBreeds = async () => {
const breeds = getBreeds()
.then(response => {
if (response.data.message) {
console.log(`Got ${Object.entries(response.data.message).length} breeds`)
}
})
.catch(error => {
console.error(error)
})
}

countBreeds()

Related TILs

Tagged:

TIL filtering DOM elements when you web-scrape

I love web-scraping. One core technique you have to master is stripping HTML from a string.

TIL a quick recipe involving Axios and Cheerio

A quick recipe to http request an api and use cheerio to web-scrape it

TIL a quick recipe involving Axios and Cheerio

A quick recipe to http request an api and use cheerio to web-scrape it