XPathOnUrl

This feature requires SeoTools Pro.

=XPathOnUrl(
   string url, 
   string xpath, 
   string attribute, 
   string xmlHttpSettings, 
   string mode
) : vector


Purpose

Fetches url and returns the (array) result from XPath expression.

You can use XPathOnUrl on any XML resource.


Xpath

XPath queries has to be in lower case. So /HTML/BODY/A won't work.


Attribute (optional)

The optional attribute allows you to retreive the value of an attribute of the specified node. Xpath /foo/@bar returns the inner text of node foo. To get attribute bar you specify:

=XPathOnUrl(url,"/foo","bar").

XmlHttpSettings (optional)

You can control the HTTP request (such as header and form variables) using the xmlHttpSettings. See HttpSettings.


Mode (optional)

The output can be extracted in raw HTML format:

=XPathOnUrl(url,"//div[1]",,"html").


Dump

Fetches the url and returns the (vector) result from xpath expression.


Local files

You can also parse local files using XPathOnUrl using either absolute or relative (to spreadsheet) filepaths:

file:///C:/path/to/file.xml
file:///path/relative/workbook.xml
file:///../../path/relative/workbook.xml

See: DirectoryList


Examples

Get country where website (or ip) is hosted

Using the GeoIPService from webservicex.net and ResolveIp we can easily get the country where a website is hosted.

=XPathOnUrl("http://www.webservicex.net/geoipservice.asmx/GetGeoIP?
IPAddress="&ResolveIp("http://offerta.se"),"/geoip/countryname")
=>"Sweden"

Return number of nodes

Retreive the number of links on a page:

=XPathOnUrl("http://nielsbosma.se","count(//a)")

Alternative to Dump and Resize

=XPathOnUrl("http://www.google.com/search?
q=dogs","(//h3[@class='r']/a)[1]","href")

This will reference the first node. To get all results in a column, you first create a column (in say column A) with values 1..10 and use the following formula:

=XPathOnUrl("http://www.google.com/search?q=dogs"
,"(//h3[@class='r']/a)["&A1&"]","href")

See

Cookbook

Guides

Related Functions


Get help with this function in the community →