Site verify your legitimacy throu your activity, i think it is mouse movement etc.
I have made it work on firefox.
This is function for changing user agent on firefox, but you can use FirefoxOptions in exchange that.
I usually use this with custom class so it is reason why self is there but you can use it as standalone function with no trouble.
def change_agent(self:webdriver.Firefox, agent):
self.get('about:config')
if self.find_elements(By.CLASS_NAME, 'primary'):
self.find_element(By.CLASS_NAME, 'primary').click()
self.find_element('id', 'about-config-search').send_keys('general.useragent.override')
time.sleep(0.1)
if self.find_elements(By.CLASS_NAME, 'has-user-value'):
self.find_element(By.CLASS_NAME, 'has-user-value').find_element(By.TAG_NAME, 'button').click()
else:
self.find_element(By.ID, 'prefs').find_element(By.XPATH,
'/html/body/table/tr/td[1]/form/label[3]/input').click()
self.find_element(By.ID, 'prefs').find_element(By.TAG_NAME, 'button').click()
self.find_element(By.TAG_NAME, 'body').send_keys(agent)
self.find_element(By.CLASS_NAME, 'has-user-value').find_element(By.TAG_NAME, 'button').click()
return True
Here is some other function to make code more readable:
def decode_img(img_path):
img = cv2.imread(img_path)
qcd = cv2.QRCodeDetector()
url = qcd.detectAndDecode(img)[0]
return url
def rsleep(f=1, s=3):
sleep(random.randint(f * 100, s * 100) / 100)
def random_scroll(driver):
driver.execute_script(
f"document.documentElement.scrollTop = document.body.scrollTop = {random.randint(100, 600)}")
To prevent being flagged as boot I have applied random sleep, yeah... it is probably not enough for a reliable solution so it is a good idea to apply additional long mouse click here you have an example how to accomplish that.
if __name__ == "__main__":
driver = webdriver.Firefox()
change_agent(driver, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0")
driver.get("https://www.tiktok.com")
rsleep(5, 7)
# get cookie banner shadowroot
shadow = driver.execute_script('return arguments[0].shadowRoot.children',
driver.find_element(By.TAG_NAME, 'tiktok-cookie-banner'))
butt = []
for el in shadow:
butt.extend(el.find_elements(By.TAG_NAME, 'button'))
# allow cookie
butt[-1].click()
driver.refresh()
# few random scrol
[random_scroll(driver) for x in range(5)]
driver.execute_script(f'document.querySelector("[data-e2e=nav-login-button]").click();')
rsleep()
driver.execute_script(f'document.querySelector("a[href*=qrcode").click();')
rsleep(3, 4)
w = driver.find_element(By.CSS_SELECTOR, "div[data-e2e=qr-code]")
w.screenshot('testqr.png')
url = decode_img('testqr.png')
At this point you can check for "undefined" in url.
Obviously, because this file is now saved in storage you can run the whole process on remote server and send qrcode through socket/ provide it via flask etc.
ps. Probably you need to change user_agent string for it to work