【问题标题】:Improve reCaptcha 2.0 solving automation script (Selenium)改进 reCaptcha 2.0 解决自动化脚本(Selenium)
【发布时间】:2015-11-21 19:47:57
【问题描述】:

我用 selenium 代码编写了一个 python 来解决new behaviour captcha。但是在完全模仿用户行为方面缺乏一些东西:代码可以定位并点击验证码,但在此之后谷歌设置了额外的图片检查

这不容易自动化。如何改进代码以在不检查图片的情况下立即解决验证码(让 google 没有提示机器人存在)?

Python 代码

from time import sleep
from random import uniform
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC

# to imitate hovering 
def hover(element):  
    hov = ActionChains(driver).move_to_element(element)
    hov.perform()
# optional: adding www.hola.org proxy profile to FF (extention is installed on FF, Win 8) 
ffprofile = webdriver.FirefoxProfile()
hola_file = '/Users/Igor/AppData/Roaming/Mozilla/Firefox/Profiles/7kcqxxyd.default-1429005850374/extensions/hola/hola_firefox_ext_1.9.354_www.xpi'
ffprofile.add_extension(hola_file) 
# end of the optional part

driver = webdriver.Firefox(ffprofile) 
url='http://tarex.ru/testdir/recaptcha/recaptcha.php'

# open new tab, also optional 
driver.find_element_by_tag_name('body').send_keys(Keys.COMMAND + 't') 
driver.get(url)

recaptchaFrame = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.TAG_NAME ,'iframe'))
        )
frameName = recaptchaFrame.get_attribute('name')

# move the driver to the iFrame... 
driver.switch_to_frame(frameName)

# *************  locate CheckBox  **************
CheckBox = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID ,"recaptcha-anchor"))
        )

# *************  hover CheckBox  ***************
rand=uniform(1.0, 1.5)
print('\n\r explicit wait for ', rand , ' seconds...')
sleep(rand) 
hover(CheckBox)

# *************  click CheckBox  ***************
rand=uniform(0.5, 0.7)
print('\n\r explicit wait for ', rand , 'seconds...')
sleep(rand)
# making click on CheckBox... 
clickReturn= CheckBox.click()
print('\n\r after click on CheckBox... \n\r CheckBox click result: ' , clickReturn)

【问题讨论】:

    标签: python selenium captcha recaptcha


    【解决方案1】:

    这是我的解决方案:

    # -*- coding: utf-8 -*-
    
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as ec
    from selenium.webdriver.support.ui import WebDriverWait
    
    driver = webdriver.Chrome()
    
    driver.get(url='https://www.google.com/recaptcha/api2/demo')
    
    # find iframe
    captcha_iframe = WebDriverWait(driver, 10).until(
        ec.presence_of_element_located(
            (
                By.TAG_NAME, 'iframe'
            )
        )
    )
    
    ActionChains(driver).move_to_element(captcha_iframe).click().perform()
    
    # click im not robot
    captcha_box = WebDriverWait(driver, 10).until(
        ec.presence_of_element_located(
            (
                By.ID, 'g-recaptcha-response'
            )
        )
    )
    
    driver.execute_script("arguments[0].click()", captcha_box)
    

    【讨论】:

    • 有效吗?它有多稳定(在google设置图像拼图之前它可以成功解决多少次)?
    • 我强烈建议先运行它...很难说它的稳定性。很多时候它取决于用户代理和代理。更重要的是,您的请求不能如此频繁 - 使用更长的延迟可能会有所帮助。
    • 代码是怎么回事?请解释每一行。
    【解决方案2】:

    你不能那样做,我认为无论如何从同一个IP完成太多请求时会使用图像障碍,所以你不能绕过它,你可以做的是使用代理

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 2020-10-25
      • 2018-12-29
      • 2014-01-10
      • 2012-07-14
      相关资源
      最近更新 更多