如何绕过TikTok机器人检测(Selenium):多账号登录受限问题排查
TikTok多账号自动化登录触发“尝试次数过多”限制
我正在开发一款TikTok自动化机器人,目标是实现多账号每小时定时上传同一视频的功能,但目前卡在登录环节——每次用Selenium登录都会触发“登录尝试次数过多,请稍后再试”的限制。5天前该功能还能正常运行,无任何报错,现在突然出现此问题。
已尝试的解决手段:
- 修改chromedriver的cdc_变量
- 使用undetected_selenium
- 集成selenium-stealth
- 更换User Agent
以上方法均未解决问题。
我通过openpyxl读取Excel中的账号数据,相关代码如下:
import os import time from selenium_profiles.driver import driver as mydriver from selenium_profiles.profiles import profiles from selenium_profiles.scripts.driver_utils import actions import undetected_chromedriver as uc from multiprocessing import Process from openpyxl import Workbook, load_workbook from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.chrome.options import Options from selenium_stealth import stealth import requests import pyautogui import random wb = load_workbook("backend.xlsx") ws = wb.active accountCounter = 1 #These Variables are changeable accountAmount = 1 hashtags = "#rich #money #luxury #millionaire #business #luxurylifestyle #lifestyle" upload_cooldown = 30 ###### mobile_emulation = { "deviceName": "Nokia N9" } s = Service("chromedriver_bypass.exe") options = Options() mydriver = mydriver() profile = profiles.Android() os.chdir("Vids") options.add_argument("start-maximized") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("useAutomationExtension", False) options.add_argument("--disable-blink-features=AutomationControlled") options.add_argument("--profile-dictonary=Default") options.add_experimental_option("mobileEmulation", mobile_emulation) #user_agent = "Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36" def findPasswords(): passwords = [] for x in range(0, accountAmount): password = ws["B" + str(x + 2)].value passwords.append(password) return passwords def findUsers(): users = [] for x in range(0, accountAmount): user = ws["A" + str(x + 2)].value users.append(user) return users def createWebDrivers(accAmount): webDrivers = [] for x in range(0,accAmount): #webDriver_x = webdriver.Chrome(service=s,options=options) webDriver_x = mydriver.start(profile, uc_driver=False) webDrivers.append(webDriver_x) return webDrivers def createWaitDrivers(webDrivers): waitDrivers = [] webDriverAmount = len(webDrivers) for x in range(0,webDriverAmount): waitDriver_x = WebDriverWait(webDrivers[x],7) waitDrivers.append(waitDriver_x) return waitDrivers webDrivers = createWebDrivers(accountAmount) waitDrivers = createWaitDrivers(webDrivers) passwords = findPasswords() users = findUsers() def login(webDriver, waitDriver, user, password): #Fixing the Bot detection webDriver.get("https://www.tiktok.com/login/phone-or-email/email") #webDriver.get("https://bot.sannysoft.com/") time.sleep(random.uniform(1,3)) y = input("Click away everything on the screen, if you have done so please write 'y'") if "y" in y: # username userBox = webDriver.find_element(By.XPATH, "/html/body/div[2]/div[1]/div/div[1]/form/div[1]/input") userBoxLocation = actions.mid_location(userBox) action = actions.touch_action_chain() action.pointer_action.move_to_location(userBoxLocation["x"], userBoxLocation["y"]) action.pointer_action.pointer_down() action.perform() time.sleep(random.uniform(1,3)) for char in user: waitDriver.until(EC.presence_of_element_located((By.NAME, "username"))).send_keys(char) time.sleep(random.uniform(.01, .1)) time.sleep(10) # password waitDriver.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div[1]/div/div[1]/form/div[2]/div/input"))).click() time.sleep(random.uniform(1,3)) for char in password: waitDriver.until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div[1]/div/div[1]/form/div[2]/div/input"))).send_keys(char) time.sleep(random.uniform(.1, .2)) time.sleep(15) waitDriver.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div[1]/div/div[1]/form/button"))).click()
内容的提问来源于stack exchange,提问作者Kazuki
相关产品推荐
相关产品推荐

