0

I have been trying to tackle this on my own but after trying multiple attempts I can not figure it out.

Trying to get the image src from this (Website here):

<div class="standard-product-column-left">
                                <div class="carousel u-centred" id="carousel-wrapper" data-carousel="carousel-wrapper" data-project-b=true style="aspect-ratio:3/4;width:100%"  data-mobile-thumbnails=true >
                                    
                                        <img alt="Buy Sony PlayStation 5 Console with DualSense Controller Online at johnlewis.com" style="aspect-ratio:3/4;width:100%" loading="auto" srcset="//johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-320$ 320w, //johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-640$ 640w, //johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-640$ 1080w, //johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-640$ 1440w"
                                        sizes="(max-width: 767px) 100vw, (min-width: 768px) 50vw" src="//johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-640$" data-large-image="//johnlewis.scene7.com/is/image/JohnLewis/239052700?$rsp-pdp-port-1440$"
                                        />

The current code I am using is:

let parser = new DomParser();
let doc = parser.parseFromString(response, 'text/html');
let image = doc.getElementsByClassName('productCarousel')

if (image.length > 0) { 
    image = image[0].getElementsByTagName('img')
    if (image.length > 0) image = 'https:' + image[0].getAttribute('src')
}

Still fairly new at this so any help would be great!

Thanks you!

Lukemul69
  • 155
  • 9

0 Answers0