1

I have tried logging into "IMDB" with python selenium but it doesn't happen correctly because it needs to pass the captcha and send a 2-step verification code. if you want to log in with your own browser it doesn't need to fill the captcha

screenshots: captcha, 2-step

and this is my code:

def login(self, email, password='hi'):
        # sleep(30)
        self.get(SING_IN_URL)
        sleep(30)
        email_path = self.find_element(By.XPATH, EMAIL_BTN)
        email_path.click()
        email_path.send_keys(email)
        sleep(10)
        password_path = self.find_element(By.XPATH, PWD_BTN)
        password_path.click()
        password_path.send_keys(password)
        sleep(10)
        self.find_element(By.XPATH, '//*[@id="signInSubmit"]').click()
        sleep(10)

and this is the SING_IN_URL : https://www.imdb.com/ap/signin?openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.imdb.com%2Fregistration%2Fap-signin-handler%2Fimdb_us&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=imdb_us&openid.mode=checkid_setup&siteState=eyJvcGVuaWQuYXNzb2NfaGFuZGxlIjoiaW1kYl91cyIsInJlZGlyZWN0VG8iOiJodHRwczovL3d3dy5pbWRiLmNvbS8_cmVmXz1sb2dpbiJ9&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&tag=imdbtag_reg-20

I want to know why it just happened for selenium. and How can I solve it?

mohammad
  • 21
  • 2

1 Answers1

1

An easy workaround to avoid the login form and the captcha is to load a user profile in which you are already logged in. Then when you run driver.get(http://imdb.com/) you will be already logged in, because it uses the cookies of the user profile. Here you find a step by step tutorial on how to create a user profile in Chrome.

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("profile-directory=Profile 2")

driver = webdriver.Chrome(..., options=options)
driver.get(http://imdb.com/)
# now you are already logged in

enter image description here

sound wave
  • 3,191
  • 3
  • 11
  • 29