1+ import asyncio
2+ from crawl4ai import AsyncWebCrawler , BrowserConfig , CrawlerRunConfig , UndetectedAdapter
3+ from crawl4ai .async_crawler_strategy import AsyncPlaywrightCrawlerStrategy
4+
5+ # Example 1: Stealth Mode
6+ async def stealth_mode_example ():
7+ browser_config = BrowserConfig (
8+ enable_stealth = True ,
9+ headless = False
10+ )
11+
12+ async with AsyncWebCrawler (config = browser_config ) as crawler :
13+ result = await crawler .arun ("https://example.com" )
14+ return result .html [:500 ]
15+
16+ # Example 2: Undetected Browser
17+ async def undetected_browser_example ():
18+ browser_config = BrowserConfig (
19+ headless = False
20+ )
21+
22+ adapter = UndetectedAdapter ()
23+ strategy = AsyncPlaywrightCrawlerStrategy (
24+ browser_config = browser_config ,
25+ browser_adapter = adapter
26+ )
27+
28+ async with AsyncWebCrawler (
29+ crawler_strategy = strategy ,
30+ config = browser_config
31+ ) as crawler :
32+ result = await crawler .arun ("https://example.com" )
33+ return result .html [:500 ]
34+
35+ # Example 3: Both Combined
36+ async def combined_example ():
37+ browser_config = BrowserConfig (
38+ enable_stealth = True ,
39+ headless = False
40+ )
41+
42+ adapter = UndetectedAdapter ()
43+ strategy = AsyncPlaywrightCrawlerStrategy (
44+ browser_config = browser_config ,
45+ browser_adapter = adapter
46+ )
47+
48+ async with AsyncWebCrawler (
49+ crawler_strategy = strategy ,
50+ config = browser_config
51+ ) as crawler :
52+ result = await crawler .arun ("https://example.com" )
53+ return result .html [:500 ]
54+
55+ # Run examples
56+ if __name__ == "__main__" :
57+ asyncio .run (stealth_mode_example ())
58+ asyncio .run (undetected_browser_example ())
59+ asyncio .run (combined_example ())
0 commit comments