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

313
Views
Al usar Node Crawler, una vez que el rastreo haya terminado y no haya más enlaces. ¿Cómo disparo el código para generar resultados?

esta es la primera vez que publico aquí, así que por favor sean amables :)

Estoy usando un rastreador de nodos (que se encuentra aquí: https://www.npmjs.com/package/crawler ) para rastrear un sitio y encontrar todos los enlaces internos. El script se ejecuta y envía los enlaces a la consola. Lo que estoy tratando de hacer es detectar una vez que ha terminado y no encuentra más enlaces, entonces quiero hacer cosas como generar todos los enlaces, tal vez agregarlos al archivo de texto o a la hoja de Google. He intentado asíncrono pero estoy un poco fuera de mi alcance. El código es el siguiente

 const Crawler = require("crawler"); let obselete = []; // Array of what was crawled already let c = new Crawler(); const crawlAllUrls = async function (url) { c.queue({ uri: url, callback: function (err, res, done) { if (err) throw err; let $ = res.$; try { let urls = $("a"); // all urls Object.keys(urls).forEach((item) => { if (urls[item].type === 'tag') { let href = urls[item].attribs.href; if (href && !obselete.includes(href)) { href = href.trim(); console.log(`href is ${href}`); obselete.push(href); // Slow down the setTimeout(function() { href.startsWith(url) ? crawlAllUrls(href) : crawlAllUrls(`${url}${href}`) }, 5000) } } }); } catch (e) { console.error(`Encountered an error crawling ${url}. Aborting crawl.`); done() } done(); } }) } c.on('drain',function(){ // For example, release a connection to database. console.log("Done"); }); // Start function const start = async function(a, b) { const result = await crawlAllUrls('http://www.five12.co.uk/'); } start();
about 4 years ago · Santiago Trujillo
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!