This guide walks you through the process of setting up Selenium with the CapSolver extension to solve reCaptcha v2. The method described can also be adapted to handle other types of CAPTCHAs.
- 1. Installing Selenium and Required Components
- 2. Configuring the CapSolver Extension
- 3. Setting Up Selenium to Solve reCaptcha with CapSolver Extension
- 4. Full Code Example
First, install Selenium and the necessary components using pip:
pip install selenium
Make sure to download and set up the appropriate drivers for the browser you plan to use (e.g., ChromeDriver for Google Chrome, GeckoDriver for Firefox).
Download the CapSolver extension and unzip it into a directory named ./CapSolver.Browser.Extension
at the root of your project.
The extension provides various settings, including automatic CAPTCHA solving and proxy support. These are defined in the ./assets/config.json
file. Below is an example configuration:
{
"apiKey": "YourApiKey",
"useCapsolver": true,
"useProxy": false,
"proxyType": "http",
"hostOrIp": "",
"port": "",
"proxyLogin": "",
"proxyPassword": "",
"enabledForBlacklistControl": false,
"blackUrlList": [],
"enabledForRecaptcha": true,
"enabledForRecaptchaV3": true,
"enabledForHCaptcha": true,
"enabledForFunCaptcha": true,
"reCaptchaMode": "token",
"hCaptchaMode": "click",
"reCaptchaDelayTime": 0,
"hCaptchaDelayTime": 0,
"reCaptchaRepeatTimes": 10,
"reCaptcha3RepeatTimes": 10,
"hCaptchaRepeatTimes": 10,
"funCaptchaRepeatTimes": 10
}
- API Key: Insert your CapSolver API key in the
apiKey
field. You can obtain your API key from the CapSolver Dashboard. - Modes: For this example,
reCaptchaMode
is set totoken
, but you can also use theclick
mode for reCaptcha.
For detailed documentation on CapSolver's features, visit the CapSolver Documentation.
Now, let's set up Selenium WebDriver and configure it to use the CapSolver extension. Below is an example using ChromeDriver in Python:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os
def main():
extension_path = os.path.abspath('./CapSolver.Browser.Extension')
chrome_options = Options()
chrome_options.add_argument(f'--load-extension={extension_path}')
driver = webdriver.Chrome(options=chrome_options)
driver.get('https://www.google.com/recaptcha/api2/demo')
# Wait for the captcha to be solved automatically by the extension
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'recaptcha-demo-submit')))
# Proceed with form submission or any other actions post-captcha solving
driver.quit()
if __name__ == "__main__":
main()
The Python script provided above is ready to run. Ensure your environment is correctly set up with the necessary packages and drivers, and adjust the extension_path
if needed to point to your CapSolver extension directory.
By following these steps, you've successfully configured Selenium with the CapSolver Extension to solve reCaptcha v2 using Python. This method can be easily adapted to solve other types of CAPTCHAs by making minor adjustments.
For more information on CapSolver, check out the CapSolver Documentation or visit the CapSolver Website.
![CapSolver](https://private-user-images.githubusercontent.com/157081315/362512066-fd9449e8-a6c4-4ec3-8bd7-8d6e107f1134.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkxMjY5NzEsIm5iZiI6MTczOTEyNjY3MSwicGF0aCI6Ii8xNTcwODEzMTUvMzYyNTEyMDY2LWZkOTQ0OWU4LWE2YzQtNGVjMy04YmQ3LThkNmUxMDdmMTEzNC5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjA5JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIwOVQxODQ0MzFaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hMDRiYzcxYzA0MjI1YmFiMTdlODkwZjM2Mzg3NTZmMDIwZjQ0MjVjN2Q0NjFlZTk1MmE0NTJkYjg5OGVlYmY3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.iQHKmU3fEPiZpEVo4zRZq2ZveBMrPgfNC1Zuazw2bDM)