XPathOnUrl

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

Results from the XPathOnUrl function inside Excel


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").

Mode argument


Dump

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

Example of Dump function


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

Return number of nodes

Retreive the number of links on a page:

=XPathOnUrl("https://seotoolsforexcel.com/","count(//a)")

Alternative to Dump

=XPathOnUrl("https://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("https://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 →