1
Hello, I’m hitting myself to write the code below
const request = require('request-promise')
const cheerio = require('cheerio')
var fs = require('fs')
const URL ='https://shadowarena.pearlabyss.com/en-US/Arena?battleType=0&server=sa'
async function rankingYoda(){
let rankYoda;
let ranks = []
const response = await request(URL)
const $ = cheerio.load(response)
$('.box_list_area').each((i, e) => {
const name = $(e).find('.thum_name').text()
ranks.push(name)
})
for(var i = 0; i < ranks.length; i++){
if(ranks[i]=== "YoDaSL"){
rankYoda = i+1
}
}
}
rankingYoda()
How do I do for the function async
return the value of the variable rankYoda
, and don’t come back [object Promise]
I’ve been trying for a few days to sort it out, but I can’t.
Use the operator
await
or use it as apromise
– Valdeir Psr
How can I place the operator
await
?– Caio Oliveira Felix
You can do how in this code or, in your case, use the library Sync-request
– Valdeir Psr