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

159
Views
Seleccionando un elemento por su selector css en titiritero

Estoy tratando de seleccionar un elemento de imagen usando su selector de estilo. Escribí la línea de código en Python pero tengo problemas para traducirlo a JavaScript. Aquí está mi intento hasta ahora. Tenga en cuenta que el código Python funciona. Es el js con el que estoy teniendo problemas.

 if driver.find_element_by_css_selector("img[style='object-fit: cover;']") is not None: download_url = driver.find_element_by_css_selector("img[style='object-fit: cover;']").get_attribute('src')

Y aquí está mi intento js.

 let imageArr = [] for(let post of posts) { await page.goto(post) await page.waitForTimeout(6000) if (await page.type("img[style='object-fit: cover;']") !== null) { const image = await page.evaluate(() => { document.querySelectorAll("img[style='object-fit: cover;']").forEach(img => { let imageUrl = img.getAttribute('src'); imageArr.push(imageUrl) }) }) } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que necesitas usar el selector de atributos * CSS, de MDN :

[attr*=value]: representa elementos con un nombre de atributo de attr cuyo valor contiene al menos una ocurrencia de value dentro de la cadena.

Entonces, para su código Javascript, creo que esto funcionará:

 let imageArr = [] for(let post of posts) { await page.goto(post) await page.waitForTimeout(6000) if (await page.type("img[style*='object-fit: cover;']") !== null) { const image = await page.evaluate(() => { document.querySelectorAll("img[style*='object-fit: cover;']").forEach(img => { let imageUrl = img.getAttribute('src'); imageArr.push(imageUrl) }) }) } }

Esto seleccionará todos los elementos img que tengan al menos una aparición de object-fit: cover; dentro de la cadena.

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!