Skip to content

Commit 805c498

Browse files
unclecodeclaude
andcommitted
docs: add simple anti-bot examples
- Add simple_anti_bot_examples.py with minimal code examples - Demonstrates stealth mode, undetected browser, and combined usage - Clean examples without logging for easy reference 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6a728cb commit 805c498

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)