英文:
Login into imdb with selenium and python
问题
我尝试使用Python Selenium登录"IMDB",但它无法正常进行,因为需要通过验证码并发送两步验证代码。如果您要使用自己的浏览器登录,就不需要填写验证码。
以下是您提供的代码:
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)
这是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=eyJvcGVuaWQuYXNzb2NfaGFuZGxlIjoiaW1kYl91cyIsInJlZGlyZWN0VG8iOiJodHRwczovL3d3dy5pbWRi.lm....
我想知道为什么Selenium出现了问题,以及如何解决它?
英文:
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
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?
答案1
得分: 1
一个简单的解决方法,可以避免登录表单和验证码,是加载一个已经登录的用户配置文件。然后,当你运行 driver.get(http://imdb.com/)
时,你已经登录,因为它使用用户配置文件的 cookie。在这里你可以找到关于如何在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/)
# 现在你已经登录了
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论