gpt4 book ai didi

python - 将 anticaptcha 与 selenium 集成

转载 作者:行者123 更新时间:2023-12-01 01:47:58 24 4
gpt4 key购买 nike

我正在使用 Selenium/Python 尝试填写表单,然后填写验证码。我找到了 python-anticaptcha 并购买了 10 美元的积分,一切正常,验证码出现了,但什么也没发生。我花了几个小时试图寻找答案/查阅他们的 api 和示例,但找不到任何东西。最终,验证码应该起作用,然后网站将生成一个我正在尝试进行网络抓取的表格

这就是它最终的样子,但没有任何反应,大约一分钟后它通常会退出,这就是代码

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
from python_anticaptcha import AnticaptchaClient, NoCaptchaTaskProxylessTask
import re
import pandas as pd
import os
import time
import requests

url = "https://claimittexas.org/app/claim-search"
driver = webdriver.Safari()
driver.implicitly_wait(30)
driver.get(url)

wait = WebDriverWait(driver, 30)
result = driver.find_element_by_xpath('//*[@id="lastName"]')
driver.execute_script("arguments[0].value='Al';",result)
time.sleep(2)
result.submit()

api_key = #MYAPIKEY
site_key = '6LeQLyEUAAAAAKTwLC-xVC0wGDFIqPg1q3Ofam5M' # grab from site

time.sleep(2)
client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
job.join()
token = job.get_solution_response()
requests.post(url, data={'g-recaptcha-response': token}).text

最佳答案

在 anticaptcha.com 某人的帮助下,我解决了这个问题。

api_key = '....'
site_key = '6LeQLyEUAAAAAKTwLC-xVC0wGDFIqPg1q3Ofam5M' # grab from site

client = AnticaptchaClient(api_key)
task = NoCaptchaTaskProxylessTask(url, site_key)
job = client.createTask(task)
print("Waiting to solution by Anticaptcha workers")
job.join()
# Receive response
response = job.get_solution_response()
print("Received solution", response)

# Inject response in webpage
driver.execute_script('document.getElementById("g-recaptcha-response").innerHTML = "%s"' % response)

# Wait a moment to execute the script (just in case).
time.sleep(1)

# Press submit button
driver.find_element_by_xpath('//button[@type="submit" and @class="btn-std"]').click()

关于python - 将 anticaptcha 与 selenium 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51034252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com