Get Data from Web Using Power Query
In this article
Yes, you can get data from a web page using Power Query in Excel and Power BI. Power Query has a built-in connector that lets you pull tables, lists, and other structured content directly from a URL, and you can refresh that data later with a single click.
What Power Query Is and Why It Matters
Power Query is a data connection and transformation tool included in Microsoft Excel (from Excel 2016 onward) and in Power BI Desktop. It lets you import data from dozens of sources—databases, files, folders, and web pages—and then clean, reshape, and combine that data before loading it into your workbook or report. Because the query steps are saved, you can refresh the data at any time without repeating the manual work.
For web data, Power Query is especially useful because it handles the messy parts of scraping: it parses HTML, finds tables, and can even read data embedded in JSON or XML. You don’t need to write code or copy-paste values; you just point Power Query at a URL and choose what to import.
How to Import Data from a Web Page in Excel
The exact steps vary slightly by Excel version, but the process is the same in Excel 2016, 2019, 2021, and Microsoft 365.
- Open Excel and create a new workbook or go to an existing one.
- Click the Data tab on the ribbon.
- In the Get & Transform Data group, click From Web (or From Other Sources > From Web in older versions).
- In the dialog box, enter the full URL of the page you want to use. For example,
https://en.wikipedia.org/wiki/List_of_countries_by_population. - Click OK. Power Query will connect to the page and show a preview of the data it found.
- If the page has multiple tables, you’ll see a list in the Navigator pane. Select the table you want, then click Load to load it directly into a worksheet, or click Transform Data to open the Power Query Editor first.
In Power BI Desktop, the steps are nearly identical: click Get Data, choose Web, enter the URL, and then select the table from the Navigator.
Working with the Power Query Editor
When you click Transform Data, the Power Query Editor opens. This is where you can clean up the data before loading it. Common tasks include:
- Remove columns you don’t need by selecting them and pressing Delete.
- Rename columns by double-clicking the header.
- Change data types (e.g., text to number) using the type icon in the column header.
- Filter rows with the drop-down arrows in each column.
- Sort data using the sort buttons in the column headers.
- Split columns if a column contains combined data, like “City, Country”.
- Add custom columns with formulas using the Add Column tab.
Every action you take in the editor is recorded as a step in the Query Settings pane on the right. You can click any step to see the data at that stage, or delete a step to undo it.
Refreshing Web Data Later
One of the biggest advantages of Power Query is that you can refresh the data whenever you want. In Excel, go to the Data tab and click Refresh All (or right-click a table and choose Refresh). In Power BI, use the Refresh button in the Home tab.
If you want the data to refresh automatically at a schedule, you can set that up in Power BI by publishing your report to the Power BI service and configuring a scheduled refresh. In Excel, you can set a workbook to refresh on opening, or use a VBA macro to refresh at intervals, but that requires more setup.
Note that refreshing web data requires an internet connection. If the website changes its structure, the query may break, and you’ll need to edit the steps in the Power Query Editor.
Common Problems and How to Fix Them
Web scraping with Power Query isn’t always smooth. Here are the most common issues and their fixes.
- “We couldn’t find any tables” – The page might use JavaScript to load content dynamically. Power Query only sees the static HTML. Try using the From Web connector with the Advanced option and add a custom User-Agent header, or use a different URL that serves the data directly (like an API endpoint).
- Data appears as one column – Some pages have tables that aren’t formatted as HTML tables. You may need to use the From Web connector and then parse the text using Split Column or Parse options.
- Refresh fails because the site changed – If the website updates its layout, the query steps that referenced specific columns or tables may break. Open the Power Query Editor, look at the steps, and adjust the column names or table references.
- Login required – If the data is behind a login, you can use the Basic or Windows authentication options in the connector, but you’ll need to provide credentials each time you refresh. For complex authentication (like OAuth), you may need to use a separate tool.
Power Query vs. Other Methods
Power Query is not the only way to get web data into Excel. You might also consider:
- Copy and paste – Quick for one-off data, but it doesn’t refresh and is error-prone.
- Excel’s built-in web queries – The older From Web feature (in Excel 2013 and earlier) is simpler but less flexible.
- VBA with XMLHTTP – You can write custom VBA code to fetch HTML and parse it, but it’s complex and requires programming knowledge.
- Third-party tools – Tools like import.io or Octoparse can scrape data and export to Excel, but they often have costs and may require a separate subscription.
Power Query strikes a good balance: it’s built-in, free, and powerful enough for most web scraping tasks. It’s not suitable for heavy-duty scraping of thousands of pages, but for a few tables on a few pages, it works very well.
Is It Safe and Legal to Scrape Web Data with Power Query?
Power Query is just a tool; the safety and legality depend on how you use it. When you import data from a website, you should respect the site’s Terms of Service. Some sites explicitly prohibit scraping, while others allow it for personal use. Always check the site’s robots.txt file and terms before pulling large amounts of data.
From a technical safety standpoint, Power Query only reads data; it doesn’t execute scripts on the page. That means it won’t download malicious code to your computer. However, the data itself could contain links or text that, if clicked, might lead to unsafe sites. Be cautious when interacting with imported data.
For personal or internal business use, scraping a few tables for analysis is generally low-risk. If you plan to republish the data or use it commercially, you should get permission from the website owner.
Frequently Asked Questions
Can Power Query pull data from a website that requires a login?
Yes, but it’s limited. The From Web connector supports Basic and Windows authentication. For sites with a simple username/password form, you can enter those credentials in the connector. However, many modern sites use OAuth or session cookies, which Power Query can’t handle directly. In those cases, you might need to use a browser automation tool or an API.
Why do I only see one column with all the text?
This usually happens when the web page doesn’t use HTML tables but instead uses divs or other elements to display data. Power Query can still extract the text, but you’ll need to parse it. In the Power Query Editor, use Split Column by delimiter (like a comma or pipe) or use the Parse option to convert the text into a table.
How do I refresh web data automatically in Excel?
You can set the workbook to refresh on opening by going to Data > Queries & Connections, right-clicking the query, and selecting Properties. Under the Refresh control section, check “Refresh data when opening the file.” For scheduled refreshes, you’ll need to use Power BI or a VBA macro.
Can I import data from a web API (JSON) with Power Query?
Yes. The From Web connector can read JSON responses. Enter the API URL, and Power Query will show the JSON as a table. You can then expand nested objects using the expand icon in the column headers. This is often more reliable than scraping HTML because APIs are designed for machine reading.
What if the website changes its layout? Will my query break?
Yes, it can. If the site removes a table or changes column names, the query steps that reference those elements will fail. When that happens, open the Power Query Editor, look at the error, and adjust the steps. You may need to re-select the table or rename columns. It’s a good idea to keep a backup of the original query.
Is there a limit to how much data I can pull from a web page?
Power Query itself doesn’t have a strict limit, but Excel has a row limit of about 1,048,576 rows per worksheet. If the page has more data than that, you’ll need to load it into the Data Model (Power Pivot) instead, which can handle much larger datasets. Also, very large pages may slow down the import process.