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

176
Views
No se pudo raspar el enlace a la página siguiente usando xpath en titiritero

Estoy tratando de raspar el enlace a la página siguiente de esta página web . Sé cómo raspar eso usando el selector css. Sin embargo, las cosas salen mal cuando intento analizar lo mismo usando xpath. Esto es lo que obtengo en lugar del enlace de la página siguiente.

 const puppeteer = require("puppeteer"); let url = "https://stackoverflow.com/questions/tagged/web-scraping"; (async () => { const browser = await puppeteer.launch({headless:false}); const [page] = await browser.pages(); await page.goto(url,{waitUntil: 'networkidle2'}); let nextPageLink = await page.$x("//a[@rel='next']", item => item.getAttribute("href")); // let nextPageLink = await page.$eval("a[rel='next']", elm => elm.href); console.log("next page:",nextPageLink); await browser.close(); })();

¿Cómo puedo raspar el enlace a la página siguiente usando xpath?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. page.$x(expression) devuelve una matriz de identificadores de elementos. Necesita desestructurar o acceder al índice para obtener el primer elemento de la matriz.
  2. Para obtener una propiedad de elemento DOM de este identificador de elemento, debe evaluar con el parámetro de identificador de elemento o la API de identificador de elemento.
 const [nextPageLink] = await page.$x("//a[@rel='next']"); const nextPageURL = await nextPageLink.evaluate(link => link.href);

O:

 const [nextPageLink] = await page.$x("//a[@rel='next']"); const nextPageURL = await (await nextPageURL.getProperty('href')).jsonValue();
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!