DynamicFetcher provides full browser automation capabilities using Playwright. It’s ideal for scraping JavaScript-heavy single-page applications (SPAs) and sites requiring complex user interactions.
Basic Usage
One-Off Requests
With DynamicSession
For multiple requests, useDynamicSession to keep the browser open:
Key Features
JavaScript Execution
Network Idle
Wait for all network requests to complete:Custom Page Actions
Execute custom automation before returning the response:Request Parameters
DynamicFetcher.fetch()
Advanced Features
Wait for Selectors
Wait for specific elements before returning:attached: Element exists in DOMvisible: Element is visible on pagehidden: Element exists but is hidden
Resource Blocking
Block unnecessary resources for faster loading:disable_resources=True:
font,image,mediabeacon,object,imagesettexttrack,websocketcsp_report,stylesheet
Initialization Scripts
Run JavaScript on every page creation:Real Chrome vs Chromium
Use your installed Chrome browser:CDP Connection
Connect to an existing browser instance:Custom Headers and Referer
Session Management
Basic Session
Async Session with Page Pool
Per-Request Proxy Override
Practical Examples
Infinite Scroll
Form Submission
Load More Button
Screenshot Capture
Error Handling
Best Practices
Use sessions for multiple requests
Use sessions for multiple requests
Always use
DynamicSession when making multiple requests. This keeps the browser open and maintains cookies.Block resources when possible
Block resources when possible
Enable
disable_resources=True to block images, fonts, and stylesheets for faster page loads.Set appropriate timeouts
Set appropriate timeouts
Complex SPAs may need longer timeouts. Set
timeout=60000 or higher for slow-loading pages.Use network_idle wisely
Use network_idle wisely
Only use
network_idle=True when necessary - it adds extra wait time. For most cases, load_dom=True is sufficient.Leverage page_action for complex flows
Leverage page_action for complex flows
Use
page_action instead of making multiple fetch calls for interactions on the same page.Pool browser tabs in async
Pool browser tabs in async
Use
max_pages to control concurrent tab usage in async sessions. Default is 1.Comparison with Other Fetchers
Next Steps
Stealthy Mode
Learn about StealthyFetcher for anti-bot bypass
Sessions
Master session management
Proxy Rotation
Rotate proxies automatically