IMPORTXMLformula allows you to import data from an XML or HTML document on the web. This can be useful for scraping data from websites or for importing data from APIs that return XML data. The formula takes a URL and an XPath query as inputs and returns the data that matches the query.
- How to use
- Examples of using
IMPORTXMLformula not working?
- Similar formulas to
IMPORTXML formula with the syntax shown below, it has 2 required parameters:
- url (required):
The URL of the XML or HTML document to import data from. The URL must be enclosed in quotation marks.
- xpath_query (required):
The XPath query to use to extract data from the XML or HTML document. The query must be enclosed in quotation marks.
ExamplesHere are a few example use cases that explain how to use the
IMPORTXMLformula in Google Sheets.
Scrape data from a table on a website
You can use the
IMPORTXML formula to extract data from a table on a website. First, find the XPath query for the table you want to import. Then, use the formula to import the table data into your Google Sheet.
Get data from an API
Many APIs return data in XML format. You can use the
IMPORTXML formula to extract data from these APIs and import it into your Google Sheet. Simply provide the API URL and the XPath query for the data you want to import.
IMPORTXMLnot working? Here are some common mistakes people make when using the
IMPORTXMLGoogle Sheets Formula:
One common mistake when using
IMPORTXML is providing an invalid URL. This can cause the formula to return an error or to import incomplete or incorrect data. Make sure to double-check that the URL is correct and that it points to an XML document.
Invalid XPath query
Another common mistake when using
IMPORTXML is providing an invalid XPath query. This can cause the formula to return an error or to import incomplete or incorrect data. Make sure to double-check that the XPath query is correct and that it targets the data you want to extract from the XML document.
IMPORTXML to import data from a large or complex XML document can result in slow performance or even cause the formula to time out. To avoid this, try to target only the data you need, and consider breaking up the import into smaller chunks using multiple formulas or by using the
QUERY function to filter the results.
The following functions are similar to
IMPORTXML or are often used with it in a formula:
IMPORTHTMLfunction is used to import data from a table or list within an HTML page. This function is commonly used to pull data from websites and display it in a Google Sheet.
IMPORTFEEDfunction in Google Sheets is used to import an RSS or ATOM feed and display the content in a tabular format in the sheet. It requires only the URL of the feed as a parameter.
IMPORTDATAfunction imports data from a URL in CSV or TSV format into a Google Sheet. The data is automatically refreshed by Google Sheets every hour, or you can manually refresh it by clicking on the cell and selecting 'Data' > 'Refresh data'.
You can learn more about the
IMPORTXML Google Sheets function on Google Support.