A
A
Andrew2021-08-11 22:07:09
CAPTCHA
Andrew, 2021-08-11 22:07:09

Selenium, how to fill out a form and not get banned?

There is a registration form on the site (with inputs and captcha), I'm trying to fill it out using Selenium in this way:

username_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[1]/div/input')
    username_input.send_keys(name)
    time.sleep(random.randrange(2, 4))

    email_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[2]/div/input')
    email_input.send_keys(mail)
    time.sleep(random.randrange(2, 3))

    password_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[3]/div/input')
    password_input.send_keys(password)
    time.sleep(random.randrange(1, 2))

    re_password_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[4]/div/input')
    re_password_input.send_keys(password)
    time.sleep(random.randrange(1, 2))

    # Переключение на фрейм с капчей
    driver.switch_to.frame(driver.find_element_by_id('mtcaptcha-iframe-1'))
    # WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it(By.ID, "mtcaptcha-iframe-1"))
    driver.find_element_by_id("mtcap-inputtext-1").send_keys(captcha)
    time.sleep(random.randrange(1, 4))

    # Переключение в родительский фрейм
    driver.switch_to.default_content()

    # скролл
    driver.execute_script("window.scrollTo(0, 500)")
    time.sleep(random.randrange(15, 17))
    
     # кнопка регистрации
driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[7]/div/input').click()
    time.sleep(random.randrange(33, 44))


After auto-pressing the registration button, the site gives out that "your address is blocked"

At the same time, if I run the script without filling in the captcha:
username_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[1]/div/input')
    username_input.send_keys(name)
    time.sleep(random.randrange(2, 4))

    email_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[2]/div/input')
    email_input.send_keys(mail)
    time.sleep(random.randrange(2, 3))

    password_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[3]/div/input')
    password_input.send_keys(password)
    time.sleep(random.randrange(1, 2))

    re_password_input = driver.find_element_by_xpath('/html/body/section[2]/div/div/div/div/form/div[4]/div/input')
    re_password_input.send_keys(password)
    

    time.sleep(random.randrange(10, 15))

and in time for the time slip, I manually fill in the captcha and press the registration button, then the registration proceeds normally without a ban.

What could be the problem? how to autofill entire process with selenium? what else can i try???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NN, 2021-08-12
@Ivannik20

It's hard to say why it doesn't eat captcha, but I would first replace the absolute path to the tags.
For example, through xpath(div[@class='']) and further by analogy, since the DOM structure may change.
It is also better to replace sleep with WebDriverWeb and until, there are more chances that there will be different waiting periods.
And how/what do you get the value of capcha ? maybe it makes sense to enter captcha character by character, with delays

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question