IMPORTXML (Google Sheets) Equivalent in Excel: Power Query Web Scraping

Power Query web scraping in Excel tutorial showing website data import HTML tables data transformation and automatic refresh
Turn websites into structured Excel datasets with Power Query web scraping. This practical tutorial shows you how to connect Excel to web pages, identify and import HTML tables, transform and clean the extracted data, and load it into a worksheet for analysis. You’ll also learn how to refresh web data automatically, handle changing page structures, combine imported information with other datasets, and troubleshoot common web-import issues. Ideal for Excel users, analysts, researchers, accountants, business professionals, and anyone who needs to collect web-based data without manually copying and pasting.

Google Sheets has a handy trick. Its IMPORTXML function pulls data straight from a web page into a cell. You pass a URL and an XPath, and the data lands in your sheet. Many people reach for Excel and look for the same function. However, Excel has no IMPORTXML at all. The good news is that Excel offers something more powerful instead. Power Query can scrape a web page, clean the result, and refresh it on demand.

This guide shows the Excel way to import web data. First, it maps IMPORTXML onto the Power Query tools that replace it. Then it walks through real imports, from simple tables to targeted elements. Several worked examples and a full troubleshooting section follow. By the end, you will pull live web data into Excel without a single add-in.

What IMPORTXML Did, and Excel's Answer

IMPORTXML reads part of a web page using an XPath address. That address points at a table, a list, or a single value. Excel solves the same problem with Power Query. Notably, it uses table detection or CSS selectors rather than XPath. The infographic below shows both routes side by side.

Two ways to pull data from a web page Google Sheets =IMPORTXML(url, xpath) one formula, XPath Excel From Web auto-detect tables Html.Table CSS selectors precise targeting Clean, transform, then load to the sheet — and Refresh on demand Data → From Web → Navigator → Transform → Close & Load

Power Query lives on the Data tab, under From Web. First, you paste a URL. Then a Navigator window shows every table it found. Finally, you pick one, tidy it, and load it. As a result, the data refreshes whenever you click Refresh.

From Web or Html.Table: Which to Use

Excel gives you two levels of control. The From Web button suits pages with clear tables. For precise targeting, the Html.Table function reads CSS selectors. Because of this, you can match almost anything IMPORTXML could.

Two levels of web import: FROM WEB (point and click): Data > From Web > paste URL > pick a table. Best when the page has real HTML tables. HTML.TABLE (custom M code): = Html.Table(html, {{"Price", ".product-price"}}) Uses CSS selectors, much like IMPORTXML uses XPath. Best for lists, single values, or odd layouts.
CSS selectors replace XPath here. IMPORTXML speaks XPath, while Html.Table speaks CSS selectors. Both point at parts of a page. So a selector like ".price" plays the same role as an XPath path.

Example 1: Import a Table with From Web

Start with the simplest case of all. Many pages hold plain HTML tables. For these, From Web does the work for you. In practice, it detects each table automatically. Then you simply choose the one you need. This alone replaces most IMPORTXML uses.

Point and click: 1. Go to Data > From Web. 2. Paste the page URL and press OK. 3. In the Navigator, click each table to preview it. 4. Pick the one you want, then choose Transform Data. 5. When it looks right, click Close & Load. The table now sits in your sheet, ready to refresh.

Example 2: Target Elements with CSS Selectors

Sometimes the data is not a neat table. Instead, it sits in cards, lists, or spans. Here Html.Table shines, because it reads CSS selectors. Therefore you can grab exactly the pieces you need.

Custom extraction in the formula bar: let Source = Web.Contents("https://example.com"), Html = Text.FromBinary(Source), Data = Html.Table(Html, {{"Title", "h2.product-title"}}, {{"Price", "span.price"}} ) in Data Each pair names a column and its CSS selector. This mirrors an IMPORTXML call with an XPath.

Example 3: Grab a Single Value or List

You often want just one number. A stock price or a rating is a good example. For that, you point a selector at one element. Then you drill into the first row.

One value, cleanly: let Source = Text.FromBinary(Web.Contents(url)), Grab = Html.Table(Source, {{"Value", ".rating"}}), First = Grab{0}[Value] in First The Grab step returns a small table. Then First reads the top cell from it.

Example 4: Clean the Imported Data

Web data rarely arrives tidy. It may carry symbols, spaces, or text. Fortunately, Power Query cleans it in a few clicks. Each step records itself for the next refresh.

Common cleanup steps: - Remove a currency symbol: Transform > Replace Values. - Turn text into numbers: Transform > Data Type. - Trim stray spaces: Transform > Format > Trim. - Split a joined field: Transform > Split Column. Every step is repeatable. So the next refresh cleans the fresh data the same way, with no extra effort.

Example 5: Refresh the Data Automatically

This is where Power Query beats a manual copy. The query remembers the page and every step. As a result, one click pulls fresh data. You can also refresh on a schedule. Because of this, a report never goes stale. Manual copy and paste cannot match it.

Keep it current: - Manual: Data > Refresh All, or right-click > Refresh. - On open: Query Properties > Refresh data when opening. - Timed: Query Properties > Refresh every N minutes. Because the steps are saved, each refresh repeats them. So your report stays current with almost no work.

Example 6: Pass a Parameter into the URL

Many sites change the page by the URL. A search term or a page number is common. Instead of editing the query by hand, you build the URL from a cell. Then one input drives the whole import.

Build the URL from an input: let Term = Excel.CurrentWorkbook(){[Name="Search"]}[Content]{0}[Column1], Url = "https://example.com/search?q=" & Term, Data = Web.Page(Web.Contents(Url)) in Data Type a new term in the Search cell, then Refresh. Consequently, the query pulls that result instead.

Example 7: Combine Several Pages at Once

Often the data spans many pages. A catalogue might run over ten pages, for instance. Rather than import each by hand, you loop over them. Then Power Query stacks the results into one table.

Loop across numbered pages: let Pages = {{1..10}}, Fetch = List.Transform(Pages, each Web.Page(Web.Contents( "https://example.com/list?page=" & Text.From(_)))), All = Table.Combine(Fetch) in All The list holds the page numbers you want. Then Table.Combine merges every page into one result.

Example 8: Load Straight to the Data Model

A web import can feed more than a sheet. You can send it to the Data Model instead. From there, it joins other tables in a PivotTable. As a result, scraped data powers a full report.

Send the query to the model: 1. On the last step, choose Close & Load To. 2. Pick Only Create Connection. 3. Tick Add this data to the Data Model. 4. Build a PivotTable from the model. Now the imported table behaves like any other source. So you can relate it to sales, dates, or categories.

Troubleshooting Web Imports

All three problems below are the most common. Each has a clear cause and a quick fix.

The page loads but the data is missing

Usually this means the site builds its content with JavaScript. Power Query reads only the raw HTML, so it never runs that script. As a result, data added after load stays invisible to it. First, view the page source in your browser and search for the value. If it is absent from the source, Power Query cannot reach it either. In that case, look for a data feed, an API, or a static version of the page. Those sources return real HTML that Power Query can read.

You get a 403 or access-denied error

This means the site refused the request. Many servers block tools that do not look like a browser. To fix it, add a user-agent header in Web.Contents so the request looks normal. Also check whether the page needs a login, since Power Query cannot sign in for you. Above all, review the site terms first, because some sites forbid scraping outright. When the site allows access and the header is set, the request usually succeeds.

The wrong table comes back

Sometimes the Navigator picks a table you did not want. Pages often hold several hidden tables for layout. Because of this, the first match may be the wrong one. First, click through each table in the Navigator and preview it. Then choose the one whose columns match your goal. For odd layouts, switch to Html.Table with a specific CSS selector. That selector targets one element and ignores the rest.

Frequently Asked Questions

  • Does Excel have an IMPORTXML function?+
    No, Excel has no IMPORTXML function. Instead, it uses Power Query on the Data tab. From Web imports tables, while Html.Table targets elements with CSS selectors. Together they replace IMPORTXML and add cleaning and refresh.
  • Can Power Query scrape any website?+
    Not every site, unfortunately. Power Query reads raw HTML only, so pages built by JavaScript often return nothing. Moreover, some sites block requests or forbid scraping. Always check the site terms before you import.
  • How do I use a CSS selector instead of XPath?+
    Specifically, you pass selectors to Html.Table as name and selector pairs. For example, ".price" grabs the price element. Thus a CSS selector plays the same role that an XPath plays in IMPORTXML.
  • Will the imported data stay up to date?+
    Yes, because Power Query saves every step. Therefore one click on Refresh pulls fresh data and cleans it again. You can also refresh on open or on a timer through Query Properties.