Automatically bypass CloudFlare bot detection and verification challenges
nodriver is built to be undetectable by bot protection systems like CloudFlare. This example shows you how to access CloudFlare-protected sites and handle verification challenges.
You can handle multiple CloudFlare-protected sites simultaneously:
import asyncioimport nodriver as ucasync def main(): driver = await uc.start() # Protected sites to access urls = [ "https://www.nowsecure.nl", "https://www.bet365.com", ] # Open first URL await driver.get(urls[0]) # Open additional URLs in new windows for url in urls[1:]: await driver.get(url, new_window=True) # Wait for all tabs to load for tab in driver.tabs: await tab print(f"Loaded: {tab.url}") # All CloudFlare checks pass automatically await driver.sleep(5) driver.stop()if __name__ == "__main__": uc.loop().run_until_complete(main())
For custom verification UIs, you can use template matching to find and click verification elements:
import nodriver as ucasync def main(): driver = await uc.start() tab = await driver.get("https://protected-site.com") await tab # Use custom template image for verification # The template should be a cropped image with the target in the center template_path = "verify_button_template.png" location = await tab.verify_cf(template_image=template_path, flash=True) if location: print(f"Verification element found at: {location}") driver.stop()if __name__ == "__main__": uc.loop().run_until_complete(main())
Automatically finds and clicks CloudFlare verification checkboxes:
# Basic usageawait tab.verify_cf()# With custom template imageawait tab.verify_cf(template_image="path/to/template.png")# Flash the element when found (for debugging)await tab.verify_cf(flash=True)
The verify_cf() method uses computer vision to locate verification checkboxes that are hidden from the DOM using shadow-root or web workers.
# Wait for specific elements instead of fixed delaysverification_passed = await tab.select(".verification-success")# Or use find() which auto-retriescontent = await tab.find("expected content", best_match=True)
While nodriver is very effective at bypassing bot detection, always:
Respect robots.txt and terms of service
Add reasonable delays between requests
Don’t hammer servers with rapid requests
Consider the ethical and legal implications of your automation
Add more realistic delays: Humans don’t interact instantly
Use headless mode carefully: Some sites detect headless browsers
Check your IP: You might be rate-limited or blocked at the network level
Rotate user agents: Though nodriver handles this, you can customize if needed
Check for captchas: Some sites use captchas that require human solving
nodriver is designed to be undetectable, but it’s not a magic bullet. Some advanced bot protection systems may still detect automation through behavioral analysis or require human intervention (like captchas).