Obter TypeError: selector.includes não é uma função ao raspar com cheerio e jsonframe
Estou tentando descartar um site com o seguinte código:
const cheerio = require('cheerio');
const jsonframe = require('jsonframe-cheerio');
const $ = cheerio.load('https://coinmarketcap.com/all/views/all/');
jsonframe($); // initializes the plugin
//exception handling
process.on('uncaughtException', err =>
console.error('uncaught exception: ', err))
process.on('unhandledRejection', (reason, p) =>
console.error('unhandled rejection: ', reason, p))
const frame = {
"crypto": {
"selector": "tbody > tr",
"data": [{
"name": "td:nth-child(2) > a:nth-child(3)",
"url": {
"selector": "td:nth-child(2) > a:nth-child(3)",
"attr": "href"
},
"marketcap": "tr > td:nth-child(4)",
"price": "tr > td:nth-child(5) > a:nth-child(1)",
}]
}
};
let companiesList = $('tbody').scrape(frame);
console.log(companiesList);
No entanto, recebo umaUnhandledPromiseRejectionWarning
ao executar o código de exemplo acima:
(node:3890) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: selector.includes is not a function
Alguma sugestão do que estou fazendo de errado?
Agradeço suas respostas!
ATUALIZAR
Mudei meu código para o seguinte abaixo. No entanto, só posso descartar o primeiro elemento.
Alguma sugestão de por que os outros elementos não são descartados?
const cheerio = require('cheerio')
const jsonframe = require('jsonframe-cheerio')
const got = require('got');
async function scrapCoinmarketCap() {
const url = 'https://coinmarketcap.com/all/views/all/'
const html = await got(url)
const $ = cheerio.load(html.body)
jsonframe($) // initializing the plugin
let frame = {
"Coin": "td.no-wrap.currency-name > a",
"url": "td.no-wrap.currency-name > a @ href",
"Symbol": "td.text-left.col-symbol",
"Price": "td:nth-child(5) > a",
}
console.log($('body').scrape(frame, {
string: true
}))
}
scrapCoinmarketCap()