From 805c498adf004305e09a7fbbc36a1ad63ebcc9cc Mon Sep 17 00:00:00 2001 From: unclecode Date: Thu, 17 Jul 2025 17:05:35 +0800 Subject: [PATCH] docs: add simple anti-bot examples MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- docs/examples/simple_anti_bot_examples.py | 59 +++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 docs/examples/simple_anti_bot_examples.py diff --git a/docs/examples/simple_anti_bot_examples.py b/docs/examples/simple_anti_bot_examples.py new file mode 100644 index 00000000..075ee9a2 --- /dev/null +++ b/docs/examples/simple_anti_bot_examples.py @@ -0,0 +1,59 @@ +import asyncio +from crawl4ai import AsyncWebCrawler, BrowserConfig, CrawlerRunConfig, UndetectedAdapter +from crawl4ai.async_crawler_strategy import AsyncPlaywrightCrawlerStrategy + +# Example 1: Stealth Mode +async def stealth_mode_example(): + browser_config = BrowserConfig( + enable_stealth=True, + headless=False + ) + + async with AsyncWebCrawler(config=browser_config) as crawler: + result = await crawler.arun("https://example.com") + return result.html[:500] + +# Example 2: Undetected Browser +async def undetected_browser_example(): + browser_config = BrowserConfig( + headless=False + ) + + adapter = UndetectedAdapter() + strategy = AsyncPlaywrightCrawlerStrategy( + browser_config=browser_config, + browser_adapter=adapter + ) + + async with AsyncWebCrawler( + crawler_strategy=strategy, + config=browser_config + ) as crawler: + result = await crawler.arun("https://example.com") + return result.html[:500] + +# Example 3: Both Combined +async def combined_example(): + browser_config = BrowserConfig( + enable_stealth=True, + headless=False + ) + + adapter = UndetectedAdapter() + strategy = AsyncPlaywrightCrawlerStrategy( + browser_config=browser_config, + browser_adapter=adapter + ) + + async with AsyncWebCrawler( + crawler_strategy=strategy, + config=browser_config + ) as crawler: + result = await crawler.arun("https://example.com") + return result.html[:500] + +# Run examples +if __name__ == "__main__": + asyncio.run(stealth_mode_example()) + asyncio.run(undetected_browser_example()) + asyncio.run(combined_example()) \ No newline at end of file