Obtener TypeError: selector.includes no es una función al raspar con cheerio y jsonframe
Estoy tratando de eliminar un sitio web con el siguiente 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);
Sin embargo, obtengo unUnhandledPromiseRejectionWarning
cuando ejecuta el código de ejemplo anterior:
(node:3890) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: selector.includes is not a function
¿Alguna sugerencia de lo que estoy haciendo mal?
Agradezco tus respuestas!
ACTUALIZAR
Cambié mi código a lo siguiente a continuación. Sin embargo, solo puedo desechar el primer elemento.
¿Alguna sugerencia de por qué los otros elementos no se desechan?
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()