Using Google Sheets, I am trying to scrape images from a real estate website to display in a cell along side the property details. I have been able demonstrate that this is possible using a simple example, but when I try to formulate the xpath query to scrape the specific images I need I continually get an error.
As a working example I will use this webpage.
The cell references in the ImportXML command in my examples always points to this URL.
The images I want are part of a slider and easily identifiable by their class: 'rsImg rsMainSlideImage'
I attempted to scrape the first image in the slider using the following command:
=IMPORTXML(A2, "(//img[@class='rsImg rsMainSlideImage'])[1]/@src")
I continually get the error:
"Imported content is empty"
To diagnose the problem I did a simpler example:
I am able to get the first image from the page (not my target image) using the following xPath:
=IMPORTXML(A2, "(//img)[1]/@src")
This successfully displays the URL of the image.
I am able to display this image in a cell by wrapping it in the image command:
=image(IMPORTXML(A2, "(//img)[1]/@src"))
This shows that in principle I should be able to scrape an image and display it in a cell.
But I am not able to select the images I am targeting using the class without an error. This is the command that I used:
=IMPORTXML(A2, "(//img[@class='rsImg rsMainSlideImage'])[1]/@src")
Other than selecting the image based on the class attribute, I am not sure what the difference is between my example that works and the example that doesn't.
I would be very grateful for any support to get this working.