Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

214
Vistas
How to get Image src attribute value using XPath

I want to extract the image url from the tag using XPath but the only problem is it returning whole src attr using the below XPath.

Query used in Chrome inspect tool:

$x("//div[@class='specs-photo-main']//img/@src")

Output:

[src]
0: src
baseURI: "https://www.gsmarena.com/xiaomi_11i_hypercharge-11186.php"
childNodes: NodeList []
firstChild: null
isConnected: false
lastChild: null
localName: "src"
name: "src"
namespaceURI: null
nextSibling: null
nodeName: "src"
nodeType: 2
nodeValue: "https://fdn2.gsmarena.com/vv/bigpic/xiaomi-11i-hypercharge.jpg"
ownerDocument: document
ownerElement: img
parentElement: null
parentNode: null
prefix: null
previousSibling: null
specified: true
textContent: "https://fdn2.gsmarena.com/vv/bigpic/xiaomi-11i-hypercharge.jpg"
value: "https://fdn2.gsmarena.com/vv/bigpic/xiaomi-11i-hypercharge.jpg"
[[Prototype]]: Attr
length: 1
[[Prototype]]: Array(0)

Is there is a way to get the "nodeValue" of "src" attribute?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to access the first element (as you need to get the first node found) and then you can get the properties of the found node:

$x("//div[@class='specs-photo-main']//img/@src")[0].nodeValue

Or,

$x("//div[@class='specs-photo-main']//img/@src")[0].textContent

if you need to get the plain text value.

See also nodeValue vs innerHTML and textContent. How to choose? and innerText vs innerHTML vs label vs text vs textContent vs outerText.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda