I am trying to import the 1st product image using the image and importxml function in google sheets from a set of URLs. Here's an example set:
SKU URL IMPORT IMAGE FORMULA
264757-WHITE https://www.tedbaker.com/uk/p/264757-WHITE ??
246367-BLACK https://www.tedbaker.com/uk/p/246367-BLACK ??
262100-LT-BLUE https://www.tedbaker.com/uk/p/262100-LT-BLUE
264793-BLACK https://www.tedbaker.com/uk/p/264793-BLACK
241424-BLACK https://www.tedbaker.com/uk/p/241424-BLACK
The formula I tried does not work:
=IMAGE(INDEX(IMPORTXML(B2,"//html/body/div[1]/main/section/div[2]/div/div[1]/div[2]/img/"),1),1)
Any help will be appreciated. I just want a formula that retrieves the 1st product image from the URLs in the data set. Thank you.
CodePudding user response:
In your HTML, how about the following sample formula?
Sample formula:
=BYROW(B2:B,LAMBDA(X,IF(X<>"",IMAGE(IMPORTXML(X,"//div[@data-swiper-slide-index='0'][1]/img[1]/@data-src")),"")))
- In this case, the xpath is
//div[@data-swiper-slide-index='0'][1]/img[1]/@data-src
.
Testing:
Note:
If you want to use a formula for each cell, how about the following sample formula?
=IMAGE(IMPORTXML(B2,"//div[@data-swiper-slide-index='0'][1]/img[1]/@data-src"))