{"id":18146455,"url":"https://github.com/2captcha/selenium-recaptcha-solver-using-grid","last_synced_at":"2025-08-22T04:30:44.547Z","repository":{"id":259034746,"uuid":"873660546","full_name":"2captcha/selenium-recaptcha-solver-using-grid","owner":"2captcha","description":"Solving reCAPTCHA v2 using clicks using the grid method. Python + Selenium Example","archived":false,"fork":false,"pushed_at":"2024-11-14T12:54:19.000Z","size":2885,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-14T13:41:08.450Z","etag":null,"topics":["2captcha","anti-captcha-selenium","browser-automation","captcha-automation-using-selenium","handle-captcha-in-selenium","how-to-solve-recaptcha","python","python-selenium-captcha","recaptcha-bypass","recaptcha-example","recaptcha-solver","recaptcha-solver-api","recaptcha-v2-solver","selenium","selenium-avoid-captcha","selenium-bypass-recaptcha","selenium-captcha","selenium-recaptcha","selenium-recaptcha-solver","selenium-solve-captcha"],"latest_commit_sha":null,"homepage":"https://2captcha.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2captcha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-16T14:23:11.000Z","updated_at":"2024-11-14T12:54:23.000Z","dependencies_parsed_at":"2024-10-21T23:11:11.821Z","dependency_job_id":null,"html_url":"https://github.com/2captcha/selenium-recaptcha-solver-using-grid","commit_stats":null,"previous_names":["2captcha/selenium-recaptcha-solver-using-grid"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2captcha%2Fselenium-recaptcha-solver-using-grid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2captcha%2Fselenium-recaptcha-solver-using-grid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2captcha%2Fselenium-recaptcha-solver-using-grid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2captcha%2Fselenium-recaptcha-solver-using-grid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2captcha","download_url":"https://codeload.github.com/2captcha/selenium-recaptcha-solver-using-grid/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230556207,"owners_count":18244620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2captcha","anti-captcha-selenium","browser-automation","captcha-automation-using-selenium","handle-captcha-in-selenium","how-to-solve-recaptcha","python","python-selenium-captcha","recaptcha-bypass","recaptcha-example","recaptcha-solver","recaptcha-solver-api","recaptcha-v2-solver","selenium","selenium-avoid-captcha","selenium-bypass-recaptcha","selenium-captcha","selenium-recaptcha","selenium-recaptcha-solver","selenium-solve-captcha"],"created_at":"2024-11-01T21:07:48.137Z","updated_at":"2024-12-20T08:25:56.690Z","avatar_url":"https://github.com/2captcha.png","language":"Python","readme":"# reCAPTCHA Solver Using 2Captcha and Selenium\n\nThis project automates [bypass Google reCAPTCHA] v2 with image challenges (3x3 and 4x4) using the 2Captcha service \n([captcha solver]) and Selenium WebDriver. The script programmatically interacts with reCAPTCHA, retrieves data for \nsolving, sends it to [reCAPTCHA solver] for processing, and then submits the solution.\n\n![bypass_recaptcha_v2_selenium_final2.gif](media%2Fbypass_recaptcha_v2_selenium_final2.gif)\n\n2Captcha service allows you to bypass any CAPTCHA using Selenium. You can find more details on [Selenium captcha solver] page.\n\nIf you are using JavaScript, we also have a similar example for JavaScript Puppeteer, the example is in the [reCAPTCHA Solver using 2Captcha and Puppeteer] repository.\n\n\n## Features\n\n- **Selenium WebDriver**: Interacts with the browser and manipulates elements on the reCAPTCHA page.\n- **2Captcha API**: Solves image-based captchas using artificial intelligence.\n- Handles both **3x3** and **4x4** captchas with custom logic for each.\n- Modular design with separated logic into helper classes for easy code maintenance and future expansion.\n- Tracks image updates and handles captcha error messages efficiently using custom error handling.\n\n## Code Structure\n\nThe project is structured as follows:\n\n- **`utils/actions.py`**: Contains the `PageActions` class, which encapsulates common browser actions (clicking, switching frames, etc.).\n- **`utils/helpers.py`**: Contains the `CaptchaHelper` class, responsible for solving captchas, executing JS, and handling captcha error messages.\n- **`js_scripts/`**: JavaScript files that extract captcha data and track image updates.\n\n## Usage\n\n### Clone:\n\n```\ngit clone git@github.com:2captcha/selenium-recaptcha-solver-using-grid.git\ncd selenium-recaptcha-solver-using-grid\n```\n\n### Requirements\n\n- Python \u003e= 3.6\n- Installed Selenium WebDriver (for Chrome)\n- [2Captcha account][2captcha] and API key\n- Required Python libraries:\n  - `selenium`\n  - `twocaptcha-python`\n```bash\npip install -r requirements.txt\n```\n\n### Configure:\n\nSet the `APIKEY` environment variable. You can get the `APIKEY` value in your personal [2captcha account][2captcha].\n\n`export APIKEY=your_api_key`\n\nYou can also set the value of `APIKEY` directly in the code. To do this, modify the `apikey` value in the following file: [main.py, line 10].\n\n### Example Command\n```bash\npython main.py\n```\n\n## How It Works\n\n1. **Browser Initialization:** A browser is opened using Selenium WebDriver.\n2. **Captcha Data Retrieval:** JavaScript extracts the image tiles from reCAPTCHA and sends them to the 2Captcha service for solving.\n3. **Captcha Submission:** Once a solution is received from 2Captcha, Selenium simulates clicking on the correct image tiles based on the solution.\n4. **Final Submission:** The solution is submitted once the captcha is solved.\n\n## Captcha Solving Logic\n\n- **3x3 Captchas:** Previous captcha ID (previousID) is saved to speed up solving when images are updated.\n- **4x4 Captchas:** No previousID is saved, and each solution is processed from scratch.\n- **Error Handling:** Messages like “Please try again” are handled, and the solving process is retried if needed.\n\n## Modular Design\n\nThe project follows a modular design for better maintainability:\n\n- **PageActions Class:** Handles general browser interactions like switching to iframes, clicking elements, and returning focus to the main content.\n- **CaptchaHelper Class:** Encapsulates captcha-specific logic, such as solving the captcha via 2Captcha API, handling error messages, and executing JavaScript in the browser.\n\n## JavaScript Scripts\n\n- `get_captcha_data.js`: Extracts captcha image tiles for solving. The source code of the script is located here https://gist.github.com/kratzky/20ea5f4f142cec8f1de748b3f3f84bfc\n- `track_image_updates.js`: Monitors requests to check if captcha images are updated.\n\n\u003c!-- Shared links --\u003e\n[2captcha-demo]: https://2captcha.com/demo\n[recaptcha-v2-demo]: https://2captcha.com/demo/recaptcha-v2\n[selenium]: https://pypi.org/project/selenium/\n[2captcha-python]: https://github.com/2captcha/2captcha-python\n[reCAPTCHA Solver using 2Captcha and Puppeteer]: https://github.com/2captcha/puppeteer-recaptcha-solver-using-clicks\n[main.py, line 10]: ./main.py#L10\n[bypass Google reCAPTCHA]: https://2captcha.com/p/bypass-recaptcha\n[captcha solver]: https://2captcha.com/\n[reCAPTCHA solver]:https://2captcha.com/\n[Selenium captcha solver]: https://2captcha.com/p/selenium-captcha-solver\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2captcha%2Fselenium-recaptcha-solver-using-grid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2captcha%2Fselenium-recaptcha-solver-using-grid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2captcha%2Fselenium-recaptcha-solver-using-grid/lists"}