How to fix tiktok selenium robot detection

Question:

How to fix TikTok selenium robot detection

Background-Info


I’m creating a python selenium bot to do things on the TikTok website. The user will log in manually so the website detecting mouse movement and typing speed is irrelevant.The issue is, is that I can’t log in while using selenium

What I’ve tried


  • I’ve tried logging in normally without selenium in incognito mode on chrome with the same Mac address, IP address, and same login details (Which worked!!)

  • I’ve tried using random user agents in selenium (Which didn’t Work)

  • I’ve tried adding the following chrome options

options.add_argument("start-maximized")

# Chrome is controlled by automated test software
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)

# avoiding detection
options.add_argument('--disable-blink-features=AutomationControlled')

What I want


I want to be able to log in without TikTok saying Too many log-in attempts. Try again later and for more clarification, I can log in normally without selenium same everything and it works it just doesn’t work while in selenium.


Heres is the code for starting selenium

post = "https://www.tiktok.com/@smoothmovesranch/video/7091224442243681579"

myProxy = ""

#configuration
options = Options()
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = myProxy
prox.ssl_proxy = myProxy

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)

options.add_argument("window-size=1400,600")
options.add_argument("--incognito")

driver = webdriver.Chrome(executable_path = os.path.join(os.getcwd(), 'chromedriver'), options=options)

#opens tiktok login page
driver.get('https://www.tiktok.com/login/phone-or-email/email')
Asked By: Caminero

||

Answers:

A few things that might help:

  1. Make sure your proxy is changing during every login attempt.

  2. For every instance of a new login create a new webdriver environment either with the same proxy or a new one.

  3. Add random wait times. For example instagram will restrict accounts that they suspect of botting. To fix this one solution is to make the selenium instance preform different clicking actions at different times. i.e. having a wait time fluctuating between a few seconds can do the trick.

  4. Also this code may help with too many login attempt issues. In short it helps selenium disguise itself better to the website servers when navigating the site.

     user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'    
     options.add_argument('user-agent={0}'.format(user_agent))
    
Answered By: Andrew Horowitz