Mefitico
Mefitico

Reputation: 1116

Multiple indexes in XPath in Google Sheets importxml

I'm using some data from Bloomberg into a Google spreadsheet, two of the lines read as:

=importxml("https://www.bloomberg.com/quote/ELIPCAM:BZ";"(//span)[28]")
=importxml("https://www.bloomberg.com/quote/ELIPCAM:BZ";"(//span)[31]")

However, there is a large number of importxml and importhtml over all, and many of them querying the same web page. As a result, too many cells are in eternal "Loading..." state. Google even presents the message:

"Loading data may take a while because of the large number of requests. Try to reduce the amount of IMPORTHTML, IMPORTDATA, IMPORTFEED or IMPORTXML functions across spreadsheets you've created."

So, is there any way to merge requests as above? For sure I could open a new tab and import everything (i.e. use only "(//span)" for the query), but other than being messy, I'm afraid I'd still be querying more than I need. ideally, there should be some query for multiple numbered nodes, something like "(//span)[28,31]", but this obviously returns an error.

Upvotes: 2

Views: 2006

Answers (2)

player0
player0

Reputation: 1

use | between your XPaths like:

=IMPORTXML("https://www.bloomberg.com/quote/ELIPCAM:BZ", 
 "(//span)[28] | (//span)[31]")

0

Upvotes: 1

Jack Fleeting
Jack Fleeting

Reputation: 24930

Try it this way and see if it works:

=importxml("https://www.bloomberg.com/quote/ELIPCAM:BZ","(//span)[position()=28 or position()=31]")

Upvotes: 2

Related Questions