将反验证码与硒集成 [英] Integrating anticaptcha with selenium

查看:62
本文介绍了将反验证码与硒集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Selenium/Python 尝试填写表格,然后填写 recaptcha.我找到了 python-anticaptcha 并购买了 10 美元的积分,一切正常,验证码出现,但没有任何反应.我试图寻找几个小时的答案/咨询他们的 api 和示例,但找不到任何东西.最终,验证码应该可以工作,然后网站会生成一个表格,我正在尝试对其进行网络抓取

I am using Selenium/Python to try and fill out a form and than fill out the recaptcha. I found python-anticaptcha and bought $10 in credits, and everything is working, the captcha comes up, but than nothing happens. I tried to look for answers for a few hours/consulted their api and examples, but could not find anything. Ultimately, the captcha should work and then the website would generate a table which I am trying to web-scrape

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

This is what it ends up looking like, but nothing happens and after a minute or so it usually quits, this is the code

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 上有人的帮助下,我解决了这个问题.

With the help of someone at anticaptcha.com, I solved this issue.

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()

这篇关于将反验证码与硒集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆