Issues with IMPORTXML function in Google Sheets

I’m stuck with a problem in my spreadsheet. A website I was pulling data from changed its layout. Now my old formula doesn’t work anymore. Here’s what I’ve tried:

=IMPORTXML("example.com/page", "//div[@class='stat-value']")

I even attempted using a full XPath, but no luck:

=IMPORTXML("example.com/page", "//html/body/div[1]/div[2]/div/div[1]/div/div[3]/span")

Any ideas on how to fix this? I’m not sure what I’m doing wrong. Maybe the site is blocking scraping now? Or did the HTML structure change too much? Help would be great!

I’ve found that tweaking the XPath with functions like contains() can really help when a website’s layout changes slightly. Recently, I had an issue where the site updated its classes unexpectedly. Instead of using the exact class, I modified my query to something like:

=IMPORTXML(“example.com/page”, “//div[contains(@class, ‘stat’)]//span”)

This approach is more flexible. Also, double-check if the data is loaded by JavaScript. If so, you might need to switch to Google Apps Script to fetch the content.

It appears that the website’s HTML structure has changed or there might be measures in place to prevent scraping. Based on my experience, I would suggest reviewing the source code with browser developer tools to verify the updated structure and adjust your XPath accordingly. An alternative approach is to use IMPORTHTML if the content is laid out in a table, or consider using Apps Script with UrlFetchApp for more robust data retrieval when the page relies on dynamic content.

hey olivias, maybe try using the browser’s inspect tool to check the new structure? sometimes websites change their html and mess up our formulas. if that doesn’t work, u could try a different approach like IMPORTHTML or even Google Apps Script. good luck!