How to Automate Website Data Retrieval in Excel using Power Query
Question details
The user wants to automate the extraction of structured data from websites into a spreadsheet and needs to know the best tools for handling logins, changing layouts, and exporting to CSV.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Importing structured table data from web pages into a spreadsheet, potentially navigating authentication, and ultimately saving the data as a CSV file.
- Observed behavior
- Evaluating whether to use Excel VBA or Power Query to automate browser interactions, handle login screens, and retrieve web data efficiently.
Verify that the target website permits automated data retrieval in its Terms of Service, and ensure you have the correct URL and login credentials if authentication is required.
Use Power Query to Extract Structured Web Data
Power Query is the most reliable and user-friendly tool for importing structured data tables from web pages into Excel.
Power Query is highly recommended over VBA for simple web scraping because it handles data extraction and transformation natively without complex coding. It can also be refreshed easily with a single click.
Navigate to the 'Data' tab on your Excel ribbon. Click on 'Get Data', select 'From Other Sources', and then choose 'From Web'.
In the dialog box that appears, paste the URL of the website containing the data you want to retrieve and click 'OK'.
The Navigator window will display all available tables found on the webpage. Select the table(s) you need and click 'Load' to import the data into your worksheet.
Once the data is loaded into your sheet, go to 'File' > 'Save As'. Choose your destination folder and select 'CSV (Comma delimited)' from the 'Save as type' dropdown menu to export the data.

Use APIs or Automation Frameworks for Complex Websites
For websites with complex authentication, dynamic JavaScript content, or stringent security controls, standard Power Query or VBA may not be sufficient.
Import and Export Web Data Easily with WPS Office
WPS Spreadsheet provides powerful built-in tools for importing external data. You can seamlessly connect to web queries, manage structured data, and export your worksheets to CSV format with a highly intuitive interface.
- 1. Open Data Import Tool: Launch WPS Spreadsheet, go to the 'Data' tab on the top ribbon, and click on 'Import Data'.
- 2. Connect to Web Source: Select the option to import from a Web Query, and enter the URL of the target website into the address bar.
- 3. Select and Import: Choose the specific data tables you want to extract from the webpage preview, then click 'Import' to place the data into your spreadsheet.
- 4. Save as CSV: Click the 'Menu' button, select 'Save As', choose 'Other Formats', and select 'CSV (Comma delimited)' to export your web data.

Frequently Asked Questions
Can Power Query handle websites that require a login?
Yes, Power Query supports basic authentication methods. When you connect to a URL, you can select 'Basic', 'Windows', or 'Web API' credentials. However, for complex web forms, CAPTCHAs, or multi-factor authentication, Power Query might fail, and you may need to use an API or a tool like Selenium.
Why is Power Query generally preferred over VBA for scraping?
Power Query is specifically built for extracting, transforming, and loading (ETL) structured data. It requires no complex coding, handles data formatting natively, and is much less likely to break when website layouts change compared to VBA macros relying on rigid HTML structures.
How do I automatically save my imported web data as a CSV file in Excel?
Once your web data is imported via Power Query, you can save it manually by going to File > Save As and choosing CSV. To fully automate this, you can write a short VBA macro that refreshes the Power Query connection and then uses the 'ActiveWorkbook.SaveAs' command to output the file in the xlCSV format.
What if the website data changes dynamically and isn't captured by Power Query?
If a website uses JavaScript to load data dynamically as you scroll, standard Power Query will only see the initial raw HTML. You can work around this by inspecting the webpage's network traffic (using browser Developer Tools) to find the underlying JSON data API URL and using that URL in Power Query instead.




