I am new to JavaScript and I am having troubles with my web-scraper program. I followed a tutorial to get cyptocurrencies value out of a website, but for some reasons I can’t read the variable “price” outside of my function.
Here’s my code
const axios = require("axios")
const cheerio = require("cheerio")
const{ Routes } = require("discord-api-types/v9");
const { parse } = require("dotenv");
async function getPriceFeed() {
try {
const siteUrl = "https://coinmarketcap.com/currencies/raptoreum/"
const {data} = await axios({
method : "GET",
url: siteUrl,
})
const $ = cheerio.load(data)
const elemSelector = "#__next > div.bywovg-1.fUzJes > div.main-content > div.sc-57oli2-0.comDeo.cmc-body-wrapper > div > div.sc-16r8icm-0.eMxKgr.container > div.n78udj-0.jskEGI > div > div.sc-16r8icm-0.kjciSH.priceSection > div.sc-16r8icm-0.kjciSH.priceTitle > div"
$(elemSelector).each((parentIdx, parentElem) => {
$(parentElem).children().each((childIdx, childElem) =>{
var price = $(parentElem).text();
return price;
})
})
}catch(err) {
console.error(err)
}
};
console.log(price)
Thank you for your help,
Vicriya