I’m experiencing issues when trying to retrieve information from a retail site using the importXML function in Google Sheets. I encounter an error that states “The xPath query given could not be evaluated,” and I’m uncertain about the reason behind it.
Here’s my code:
=importXML("https://www.amazon.com/product-name/dp/B123456789", "//span[@class='price-current']")
Interestingly, similar importXML commands work on other webpages without any problems. I can successfully gather data from various sites, but this particular retailer’s page keeps returning the same error.
Has anyone else faced this issue? What factors could cause one site to behave differently concerning XPath queries? I’ve verified my syntax and confirmed that the element is present on the page.
Amazon blocks automated scraping, including Google Sheets importXML requests. They’ve got anti-bot measures that detect and shut down these queries. I ran into this same problem last year trying to pull pricing data from Amazon listings. The XPath error happens because Amazon’s servers spot the automated request and send back blocked content instead of the actual page. That’s why your syntax works fine on other retail sites but dies on Amazon. You’ll have better luck with smaller e-commerce sites that don’t have strict scraping policies, or just use Amazon’s official API if that works for what you’re doing.
I feel you on this! Amazon’s really tough with importXML requests - their systems are built to block automated scraping. Even if your xpath is perfect, you’ll just hit a wall. I’d try other sites instead or grab a web scraper that can get around Amazon’s blocks.
Your XPath selector probably doesn’t match Amazon’s actual HTML structure. Amazon constantly changes their class names and uses dynamically generated ones that are different from what you see in the browser inspector. I ran into the same problem and found that most e-commerce sites load pricing through JavaScript after the page loads - so importXML only grabs the empty skeleton before the price populates. Also, Amazon serves different HTML to different user agents, so Google Sheets might get completely different markup than your browser sees. Check if the price element exists in the raw HTML source instead of the rendered page to confirm this.