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

171
Views
"TypeError: $ no es una función" al intentar usar cheerio como jquery

Estoy tratando de hacer un bot para verificar si un artículo está en stock. Lo basé en este video https://www.youtube.com/watch?v=57TEZq8O360 , pero cambié la URL. Aunque puedo consolar. registrar el contenido de la página web cuando trato de usar cheerio como jquery, aparece este error "Error de tipo: $ no es una función". Sé que Cheerio está instalado y funciona como lo he declarado con "const $ = require('cheerio');" y he podido usarlo en otra parte de mi archivo. ¿Hay un error tipográfico que me estoy perdiendo? Mi código roto está abajo.

 async function checkStock(page){ await page.reload(); let content = await page.evaluate(() => document.body.innerHTML); console.log(content); $("link[itemprop='availability']", content).each(function(){ //error here let instock= $(this).attr('href').toLowerCase().includes("outofstock"); if(instock){ console.log("no"); } });}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesitas cargar el HTML en cheerio, y luego cheerio te dará la API $ :

 const $ = require("cheerio"); // ... async function checkStock(page){ await page.reload(); const content = await page.evaluate(() => document.body.innerHTML); const $ = cheerio.load(content); $("link[itemprop='availability']", content).each(function(){ //error here let instock = $(this).attr('href').toLowerCase().includes("outofstock"); if (instock) { console.log("no"); } }); }
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!