I'm facing the problem of "Too many attempts try later" while trying to log into tik tok using selenium. How do I fix it?

Viewed 14

I'm facing the problem of "Too many attempts try later" while trying to log into tik tok using selenium and chromedriver. I already tried to change my IP, user agent and to clear chrome cache. The most confusing part is that I can login in my account via both chrome and firefox, while chromedriver doesn't work.

The Problem:

Photo with problem

Code:

from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from fake_useragent import UserAgent


USER_AGENT = UserAgent()


def login(username, password):

        PATH = './tiktok/chromedriver'

        options = webdriver.ChromeOptions()
        options.add_argument(f'--incognito')
        options.add_argument(f'user-agent={USER_AGENT.random}')


        driver = webdriver.Chrome(executable_path=PATH, options=options) 
        driver.get('https://www.tiktok.com/')
        time.sleep(5)
        driver.find_element(By.XPATH, '/html/body/div[2]/div[1]/div/div[2]/button').click()
       
        time.sleep(3)
        log_in_method_button = driver.find_element(By.XPATH, '//*[@id="loginContainer"]/div/div/a[2]/div')
        log_in_method_button.click()

        time.sleep(1)
        change_method_to_email_or_username = driver.find_element(By.XPATH, '/html/body/div[6]/div[2]/div[2]/div[1]/div/form/div[2]/a')
        change_method_to_email_or_username.click()

        time.sleep(3)
        email_or_username_field = driver.find_element(By.XPATH, '/html/body/div[6]/div[2]/div[2]/div[1]/div/form/div[1]/input')
        password_field = driver.find_element(By.XPATH, '/html/body/div[6]/div[2]/div[2]/div[1]/div/form/div[2]/div/input')
        enter_text(username, email_or_username_field)
        
        time.sleep(3)
        enter_text(password, password_field)
        
        time.sleep(2)
        password_field.send_keys(Keys.ENTER)
        
        
        time.sleep(10)


def enter_text(text, field):

    text_to_enter_list = text.replace('', ' ').split()
    print(text_to_enter_list)
    for letter in text_to_enter_list:
        time.sleep(0.2)
        field.send_keys(letter)

if __name__ == '__main__':
    login('nickname', 'pass')

It seemed to me that the problem is about the webdriver, but webdriver re-installation didn't give any positive results. I would be grateful for any kind of help, thanks!

0 Answers
Related