将抗突变体与硒结合

时间:2018-06-26 02:56:21

标签: python selenium web-scraping recaptcha

我正在使用Selenium / Python尝试填写表单,而不是填写Recaptcha。我找到了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

1 个答案:

答案 0 :(得分:1)

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