Complex Web Scraping with Error Handling
Loop through URLs, scrape each with TryCatch error handling, and conditionally save results
Steps
| # | Activity | What it does |
|---|---|---|
| 1 | StartWebBrowser | Open browser for scraping session |
| 2 | CreateTable | Create an in-memory table to accumulate scraped rows |
| 3 | ForEachLoop | Iterate over list of URLs to scrape |
| 4 | TryCatch | Handle errors for each URL gracefully |
| 5 | IfCondition | Check if data was extracted before saving |
| 6 | TableUpsertRow | Append a scraped row to the accumulated table |
| 7 | TableExport | Export the accumulated rows to Excel |
Workflow
urls = Assign({'urls': ['https://example.com/page1', 'https://example.com/page2', 'https://example.com/page3']})
StartWebBrowser("https://example.com", "useCurrentBrowserSession")
CreateTable("allResults", schema={"columns": [{"name": "url"}, {"name": "content"}]})
for currentUrl in urls:
try:
NewChangeUrlBrowserTab(currentUrl)
pageData = GetHtmlElements("//div[@class='content']")
if pageData.length > 0:
for item in pageData:
TableUpsertRow("allResults", {"url": currentUrl, "content": "{{ item.text }}"}, append=True)
else:
WriteLine("{{ 'No data found at index ' + urlIndex }}")
except Exception as scrapeError:
WriteLine("{{ 'Error scraping URL at index ' + urlIndex + ': ' + scrapeError }}")
TableExport("allResults", "./scraped_results.xlsx", format="xlsx", sheetName="Results")