![](/img/trans.png)
[英]Solving a Recaptcha V2 with a callback function using the 2captcha service and Python Selenium/Scrapy
[英]Captcha solving with selenium and python
我正在嘗試創建一個機器人來解決網站上的驗證碼問題,我正在使用 selenium 與隱形插件和驗證碼工具。 似乎 capsolver 正在返回我的驗證碼,但是當我點擊一個復選框時,它會提示我到 select 圖像。
我的代碼:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium_stealth import stealth
import time
import json
from pathlib import Path
from captchatools import new_harvester, exceptions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions
current_url = "https://key-drop.com/en/daily-free"
harvester = new_harvester(
api_key="api key im using",
solving_site="capsolver",
captcha_type="v2",
sitekey="6Ld2uggaAAAAAG9YRZYZkIhCdS38FZYpY9RRYkwN",
captcha_url="https://key-drop.com/en/daily-free"
)
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", \["enable-automation"\])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r"C:\\WebDriver\\bin\\chromedriver.exe")
stealth(driver,
languages=\["en-US", "en"\],
vendor="Google Inc.",
platform="Win32",
webgl_vendor="Intel Inc.",
renderer="Intel Iris OpenGL Engine",
fix_hairline=True,
)
def GetCurrentUrl():
get_url = driver.current_url
global current_url
current_url = str(get_url)
driver.get("https://key-drop.com/en/daily-free")
for cookie in json.loads(Path('cookies.json').read_text()):
driver.add_cookie(cookie)
time.sleep(4)
driver.find_element(By.XPATH, '/html/body/main/div\[1\]/div/section\[1\]/div\[2\]/div\[2\]/div\[1\]/button').click()
p = driver.current_window_handle
WebDriverWait(driver, 20).until(
expected_conditions.presence_of_element_located((By.ID, 'g-recaptcha-response'))
)
try:
answer = harvester.get_token()
except exceptions.ErrWrongSitekey:
print("wrong sitekey")
except exceptions.ErrIncorrectCapType:
print("wrong captcha type")
except exceptions.ErrWrongAPIKey:
print("wrong api key")
print(answer)
driver.execute_script(
"document.getElementById('g-recaptcha-response').innerHTML = " + "'" + answer + "'")
time.sleep(3)
iframe = driver.find_element(By.XPATH, "/html/body/main/div\[2\]/div/div/div/div/div/div/iframe")
driver.switch_to.frame(iframe)
WebDriverWait(driver, 20).until(
expected_conditions.presence_of_element_located((By.CLASS_NAME, 'recaptcha-checkbox-checkmark'))
)
driver.find_element(By.XPATH, "/html/body/div\[2\]/div\[3\]/div\[1\]/div/div/span/div\[1\]").click()
time.sleep(120)
應該插入響應的元素(至少我是這么認為的):
<textarea id="g-recaptcha-response" name="g-recaptcha-response" class="g-recaptcha-response" style="width: 250px; height: 40px; border: 1px solid rgb(193, 193, 193); margin: 10px 25px; padding: 0px; resize: none; display: none;"></textarea>
我嘗試使用 captchatools 異常,沒有收到任何錯誤,所以 api 請求應該沒問題。 我是初學者,老實說我完全迷路了,我們將不勝感激! 謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.