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

140
Views
DOM HTML Extract with javascript

I'm trying to extract information from an html page, specifically I'm trying to get the "src" url below in bold (**)

<div class="row d-block align-end" data-v-1a4e2f4c="">
<div index="0" class="row" data-v-744a5232="" data-v-1a4e2f4c="">
    <div class="col-lg-2 col-3" data-v-744a5232=""><a
            href="/libro-el-peligro-de-estar-cuerda/9788432240645/12789134" title="EL PELIGRO DE ESTAR CUERDA"
            class="py-2" data-v-744a5232=""><img title="el peligro de estar cuerda-9788432240645"
                alt="el peligro de estar cuerda-9788432240645"
                **src="https://imagessl5.casadellibro.com/a/l/t1/45/9788432240645.jpg"**
                data-src="https://imagessl5.casadellibro.com/a/l/t1/45/9788432240645.jpg" width="" height=""
                class="show-shadow cdl-img active" style="max-height:undefinedpx;max-width:undefinedpx;"
                data-v-744a5232=""></a></div>

The code I'm using does not seem to do the trick, although it works when extracting the title:

  let resultImg = xmlDoc.evaluate('./div/div/a/img[@src]', node, null, XPathResult.FIRST_ORDERED_NODE_TYPE);
    let bookImgSrc = resultImg.singleNodeValue.src;
    imgCard.src = bookImgSrc.replace('mtiny', 'large');
    divCard.appendChild(imgCard);
    console.log(imgCard);

Could someone point out what is wrong in the code and how to get the src url?

I suspect the xPathResult may be wrong.

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

0

you can select the element then use this following code :

var myElementSrc = mySelectedElement.src ;

this is simple.

about 4 years ago · Juan Pablo Isaza Report

0

probably your xpath is not correct. I tried to use "//div/div/a/img and it works

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!