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

102
Views
Intentando raspar un enlace de la página web con titiritero

No entiendo por qué no puedo recuperar el enlace href de esta página con titiritero: PubChem .

Ejecuté Chrome e inspeccioné la página y encontré el Headline deseado del químico y copié el Selector que se ve así: #featured-results > div:nth-child(2) > div.box-shadow > div > div.p-md-rectangle.flex-container.flex-nowrap.width-100 > div.flex-grow-1.p-md-left > div.f-medium.p-sm-top.p-sm-bottom.f-1125 > a

y luego ejecuté este código JS con nodejs.

 const puppeteer = require('puppeteer') puppeteer.launch({ headless: true }).then(async browser => { const page = await browser.newPage() await page.goto('https://pubchem.ncbi.nlm.nih.gov/#query=MES') // const cookies = await page.cookies() // console.log(cookies) const links = await page.evaluate(() => [document.querySelectorAll('#featured-results > div:nth-child(2) > div.box-shadow > div > div.p-md-rectangle.flex-container.flex-nowrap.width-100 > div.flex-grow-1.p-md-left > div.f-medium.p-sm-top.p-sm-bottom.f-1125 > a')].map(link => link.href)) links.forEach(link => console.log(link)) await browser.close() })

Pero mi resultado es NULL. ¿Alguien podría abrirme los ojos, por favor? Gracias.

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

0

  1. Debe esperar a que aparezca el elemento.
  2. Necesita propagación ( ... ) para crear una matriz a partir del resultado de querySelectorAll() .
 const puppeteer = require('puppeteer') puppeteer.launch({ headless: true }).then(async browser => { const page = await browser.newPage() await page.goto('https://pubchem.ncbi.nlm.nih.gov/#query=MES') await page.waitForSelector('#featured-results > div:nth-child(2) > div.box-shadow > div > div.p-md-rectangle.flex-container.flex-nowrap.width-100 > div.flex-grow-1.p-md-left > div.f-medium.p-sm-top.p-sm-bottom.f-1125 > a') const links = await page.evaluate( () => [...document.querySelectorAll('#featured-results > div:nth-child(2) > div.box-shadow > div > div.p-md-rectangle.flex-container.flex-nowrap.width-100 > div.flex-grow-1.p-md-left > div.f-medium.p-sm-top.p-sm-bottom.f-1125 > a')] .map(link => link.href) ) links.forEach(link => console.log(link)) await browser.close() })
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!