Home > Mobile >  How to get this Selenium script to login without being detected?
How to get this Selenium script to login without being detected?

Time:02-01

Before this gets taken down as a duplicate, I have already tried all of the options available here: Is there a version of Selenium WebDriver that is not detectable?.

I am trying to create a Selenium bot in Python which can successfully login without getting blocked due to bot detection. My current script is below and I have created a test account for anyone to access and help me get this working. The correct answer here would ideally be a working version of this script that I can use.

Username: TestAccount
Password: StackOverflowPass1

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time
 
##### open depop 'likes' page #####

url = "https://www.depop.com/login/"

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get(url)

driver.implicitly_wait(2)
driver.get(url)
time.sleep(2)

accept_cookies = driver.find_element_by_xpath('/html/body/div[1]/div/div[3]/div[2]/button[2]')
accept_cookies.click()
time.sleep(2)

username = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/form/div[1]/input')
username.send_keys('TestAccount1')

password = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/form/div[3]/div/input')
password.send_keys('StackOverflowPass1')

login_button = driver.find_element_by_xpath('/html/body/div[1]/div/div/div[1]/form/button')
login_button.click()

CodePudding user response:

I have had the same issue with logging in to gmail. I could not solve it for a week. I am 99% sure that you can't bypass the bot detection. How I solved it:

I have created Chrome account to which my gmail will be logged in all the time (disabled 2FA). Then I just start chrome as that user. Bot detection was no more an issue when I was already logged into gmail. Maybe you should try the same, add this command to your driver class:

options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")

This path is usable for Mac or Linux OS. Also, rename "Default" to your profile id (for me, and in most cases, it was "Profile 1")

  •  Tags:  
  • Related