Attempting to parse Alexa ranking within Google Doc using =ImportXML. The following works and displays the Global rank:
=value(ImportXML(CONCATENATE("http://data.alexa.com/data?cli=10&dat=snbamz&url=",$A$4),"//@rank[1]"))
In theory the following should display the country ranking if it exists: (this doesn't work)
=ImportXML(CONCATENATE("http://data.alexa.com/data?cli=10&dat=snbamz&url=",$A$4),"//@rank[2]")
The above is the part that isn't working. It's not pulling the value of the second "rank" attribute.
I have also tried: (doesn't work)
=ImportXML(CONCATENATE("http://data.alexa.com/data?cli=10&dat=snbamz&url=",$A$4),"/country/@rank")
Help? What am I doing wrong?
Your second XPath query may never work. You're trying to query the second
@rank
attribute of an element, but there may only be one. If you want to select the second@rank
attribute in the whole document, use(//@rank)[2]
.Your alternative query does not work, as
country
is not the root element. Use//country/@rank
instead. It might be reasonable to provide the full path step by step, to prevent fetching the wrong elements/attributes (if they occur somewhere else in the document):Please be aware that principally XPath is case sensitive, although Google Spreadsheet seems to be not. Better use all caps here, as the XML input does.