TIL a quick recipe involving Axios and Cheerio
POSTED ON:
TAGS: web-scraping javascript fetch recipe mdn
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: web-scraping