Mefitico
Mefitico

Reputation: 1116

Copied XPath returns empty result?

Using this webpage for testing, and this Bloomberg page as a source for the XML string, I wat to get the NAV value that is in big numbers. If I inspect the element with Google Chrome and right-click to copy the XPath I get:

//*[@id="root"]/div/div/section[2]/div[1]/div[2]/section[1]/section/section[2]/section/div[1]/span[1]

If I copy the full XPath, then I get:

/html/body/div[6]/div/div/section[2]/div[1]/div[2]/section[1]/section/section[2]/section/div[1]/span[1]

It would be even better if something like this worked:

//span[@class="priceText__1853e8a5"]

But all these expressions, despite being marked valid by the tool, also give an empty result in the testing tool and in my Google Spreadsheet, where I use:

=importxml("https://www.bloomberg.com/quote/ZARATHU:BZ";"//span[@class='priceText__1853e8a5']")

Though I note all the queries above don't work on the spreadsheet as well.

Upvotes: 1

Views: 851

Answers (1)

Iamblichus
Iamblichus

Reputation: 19309

Looks like this website is protected against automated requests, and so it's blocking the requests from IMPORTXML. You can check that if you try to retrieve the full HTML:

=importxml("https://www.bloomberg.com/quote/ZARATHU:BZ","html")

The returned HTML content includes the following:

We've detected unusual activity from your computer network
To continue, please click the box below to let us know you're not a robot.

Related:

Edit:

The OP solved the issue by using this web scraping add-on:

=IMPORTFROMWEB("https://www.bloomberg.com/quote/ZARATHU:BZ";"//span[@class='priceText__1853e8a5']")

Upvotes: 1

Related Questions