UiPath自动化网页数据提取求助:将指定字段导出至Excel
Hey there! Let's work through this UiPath automation challenge together—since you're new to the tool, I’ll break it down into simple, actionable steps that you can follow easily.
UiPath Automation Step-by-Step Guide: Extract Portal Data to Excel
1. Pre-requisites & Setup
- First, make sure you have the necessary UiPath packages installed:
- UiPath.Excel.Activities (for Excel operations)
- UiPath.Web.Activities (for web automation)
You can grab these via the Manage Packages option in UiPath Studio—just search for the names and install them.
- Spend a minute navigating your target portal to get familiar with how records are laid out: Are they in an HTML table? Or individual cards? Knowing this will make data extraction smoother.
2. Get User Input for Record Count
- Drag an
Input Dialogactivity onto your workflow.- Set the Prompt to something like: "Please enter the number of records you want to extract:"
- Store the user's input in a string variable first, then convert it to an integer (since we’ll use it for counting). For example:
int_RecordCount = CInt(InputDialog_Result.ToString)
- Pro tip: Add a quick validation step with an
Ifactivity to check if the input is a valid number (useIsNumeric(InputDialog_Result)). If not, show a message asking the user to enter a number and loop back to the input dialog.
3. Extract Data from the Portal
How you extract data depends on how records are displayed on the portal—here are the two most common scenarios:
Scenario A: Records are in an HTML Table
- Use UiPath’s built-in Data Scraping wizard (click the Data Scraping button in the Design tab) to automate this:
- Select the first instance of CompanyName, then select the second instance—UiPath will automatically detect the table structure.
- Repeat this for BrokerName, Address, and Phone to add all required columns.
- When prompted for the maximum number of records to extract, enter your
int_RecordCountvariable. - The wizard will generate an
Extract Dataactivity, which stores the results in a DataTable (let’s call itdt_ExtractedRecords).
Scenario B: Records are in Individual Cards
- If records are in separate cards (not a table), use a loop approach:
- Use a
Find Childrenactivity to locate all record cards on the page. Set the selector to target the card container (e.g.,<webctrl tag='div' class='record-card' />), and store the results in aList<UiElement>variable likelist_AllRecords. - Add a
For Eachloop to iterate overlist_AllRecords. To limit the loop to the user-specified count, set the loop’s range toMath.Min(list_AllRecords.Count, int_RecordCount)(this avoids errors if there are fewer records than requested). - Inside the loop, use
Get Textactivities to extract each field (CompanyName, BrokerName, etc.). Make sure your selectors are relative to the current card (use theAttach Browseractivity to anchor to the portal, and build selectors that reference the card element from the loop). - Initialize a DataTable upfront with columns matching your fields, then use
Add Data Rowinside the loop to add each extracted record to the table.
- Use a
4. Export Data to Excel
- Drag a
Write Rangeactivity into your workflow.- Set the DataTable field to
dt_ExtractedRecords. - Enter your desired Excel file path (e.g.,
"C:\YourFolder\CompanyData.xlsx"). - Check the AddHeaders box—this will write your DataTable column names as the Excel header row.
- Set the DataTable field to
5. Troubleshooting Common Issues
- Unstable selectors: Avoid using fixed IDs or dynamic attributes (like random numbers) in your selectors. Instead, use stable attributes like
class,tag, orinnertextto make them more reliable. - Pagination: If the portal splits records across pages, add logic to check if you’ve extracted enough records. If not, click the "Next Page" button and repeat the extraction until you hit
int_RecordCountor run out of pages. - Data formatting: If fields like Phone have weird formatting, use string manipulation activities (like
ReplaceorTrim) to clean up the data before adding it to the DataTable.
内容的提问来源于stack exchange,提问作者Bala Ashokan




