Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

208
Views
No se puede corregir un error causado por cheerio al usar axios

Estoy tratando de obtener títulos de diferentes publicaciones de una página web usando axios y cheerio pero el script siempre arroja este error Error: cheerio.load() expects a string . ¿Cómo puedo arreglarlo?

 const axios = require('axios'); const cheerio = require('cheerio'); const startLink = 'https://old.reddit.com/r/programming/'; const getPostTitles = (link) =>{ const resp = axios.get(link); const $ = cheerio.load(resp.data); const postTitles = []; $('div > p.title > a').each((_idx, el) => { const postTitle = $(el).text() postTitles.push(postTitle) }); return postTitles; }; const results = getPostTitles(startLink); console.log(results);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Axios.get() devuelve una promesa, por lo que debe await o usar .then() para obtener el resultado. He usado la sintaxis async/await a continuación, esto mostrará los títulos de las publicaciones:

 const axios = require('axios'); const cheerio = require('cheerio'); const startLink = 'https://old.reddit.com/r/programming/'; const getPostTitles = async (link) => { const resp = await axios.get(link); const $ = cheerio.load(resp.data); const postTitles = []; $('div > p.title > a').each((_idx, el) => { const postTitle = $(el).text() postTitles.push(postTitle) }); return postTitles; }; async function testGetPostTitles() { const results = await getPostTitles(startLink); console.log(results); } testGetPostTitles();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!