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

180
Views
No se puede incluir el enlace del sitio web como parámetro al llamar a una función

Creé un script utilizando las bibliotecas de request y cheerio para obtener diferentes títulos de publicaciones y sus enlaces correspondientes de un sitio web. El guión parece estar funcionando bien. Si observa el siguiente script, puede ver que he usado getposts((item,link) => console.log({item,link})); para llamar a la función.

Ahora, la pregunta es:

¿Cómo puedo incluir startUrl (enlace del sitio web) como parámetro mientras llamo a la función manteniendo el resto de las lógicas como están?

 var request = require('request'); var cheerio = require('cheerio'); const startUrl = 'https://stackoverflow.com/questions/tagged/web-scraping'; function getposts(callback) { request(startUrl, function(error, response, html) { if (!error && response.statusCode == 200) { var $ = cheerio.load(html); $('.summary .question-hyperlink').each(function() { var items = $(this).text(); var links = $(this).attr('href'); return callback(items, links); }); } }); } getposts((item,link) => console.log({item,link}));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cree un nuevo parámetro para una URL y pase startUrl:

 var request = require('request'); var cheerio = require('cheerio'); const startUrl = 'https://stackoverflow.com/questions/tagged/web-scraping'; function getposts(url, callback) { request(url, function(error, response, html) { if (!error && response.statusCode == 200) { var $ = cheerio.load(html); $('.summary .question-hyperlink').each(function() { var items = $(this).text(); var links = $(this).attr('href'); return callback(items, links); }); } }); } getposts(startUrl, (item,link) => console.log({item,link}));
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!