Cloudscraper is a Python library built on top of the `requests` library, designed to bypass Cloudflare's anti-bot page (also known as "I'm Under Attack Mode" or IUAM). It achieves this by mimicking a real web browser, handling JavaScript challenges, and managing cookies automatically, allowing users to scrape websites protected by Cloudflare. The library is actively maintained, with frequent updates to adapt to Cloudflare's evolving security measures. The current PyPI version is 1.2.71, though a major version 3.0.0 has been released on GitHub with significant changes.
pip install cloudscraperVerified import paths — ran on the pinned version, not inferred.
The simplest way to use `cloudscraper` is by calling `cloudscraper.create_scraper()`, which returns a `CloudScraper` instance. This instance behaves similarly to a `requests.Session` object. Any requests made through this session to Cloudflare-protected websites will automatically attempt to bypass the anti-bot measures. The script includes a placeholder URL and demonstrates basic error handling for a 403 status code, which is common if Cloudflare still blocks the request. It's recommended to set a realistic User-Agent for better stealth.
Upgrade Python to 3.8 or newer. Update all project dependencies to their latest stable versions. Review `cloudscraper`'s GitHub `UPGRADE_SUMMARY.md` for specific changes if migrating an existing codebase. Use `pip install --upgrade cloudscraper` or `pip install cloudscraper>=3.0.0`.
Keep `cloudscraper` updated to the latest version. If issues persist, enable debug mode (`cloudscraper.create_scraper(debug=True)`) to diagnose. Consider adjusting scraper settings like `delay`, `browser` profile, or trying different JavaScript interpreters (e.g., Node.js if installed).
Integrate with a third-party CAPTCHA solving service (e.g., 2Captcha, Anti-Captcha) via `cloudscraper`'s built-in support. This typically requires an API key and an active subscription to the service.
For highly dynamic or heavily protected websites, consider using headless browser automation tools like Selenium or Playwright, or utilizing specialized managed scraping APIs that handle these complexities.
Install `cloudscraper` using pip: `pip install cloudscraper`. If using a virtual environment, ensure it is activated before installation. Verify the correct Python interpreter is being used.
Update `cloudscraper` to the latest version: `pip install --upgrade cloudscraper`. Consider implementing delays between requests, rotating IP addresses (proxies), or adjusting browser emulation parameters. If the issue persists, Cloudflare's protection might be too advanced for `cloudscraper` and may require alternative tools like Selenium/Playwright or specialized scraping APIs.
For Cloudflare version 2 challenges, `cloudscraper`'s free version often cannot provide an automatic bypass. One suggested solution is to integrate a third-party CAPTCHA solving service (e.g., 2Captcha, Anti-Captcha) by providing the API key to `cloudscraper.create_scraper()`. Alternatively, more robust browser automation tools (like Selenium or Playwright) might be necessary.
Upgrade your Python version to 3.7 or higher, as `cloudscraper` works best with newer Python versions. If upgrading Python is not immediately feasible, try downgrading `cloudscraper` to an older, compatible version (e.g., `pip install cloudscraper==1.2.58`).
Ensure `cloudscraper` and `js2py` are updated (`pip install --upgrade cloudscraper js2py`), and consider passing a custom `user_agent` or specific `headers` to the scraper.