使用 Selenium webdriver 和 python 登录 Google

问题描述 投票:0回答:0

我一直在使用 Selenium web 驱动程序登录时遇到问题,因为它显示我无法登录然后测试,搜索 pizza 一词,但它不会超出登录范围。我感兴趣的是能够登录。

This is the message that appears to me, Google detects that an external driver is being used

“无法登录 此浏览器或应用程序可能不安全。了解更多 尝试使用不同的浏览器。如果您已经在使用受支持的浏览器,您可以再次尝试登录。”

我使用的python代码是这样的,它与selenium 4和python 3.10.6一起使用(当然我更改了电子邮件和密码,但仍然使用这些或我的,它不会超出那个模态)

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

# Start a new instance of the browser
driver = webdriver.Chrome()

# Go to the Google sign-in page
driver.get("https://accounts.google.com/signin")

# Find the username element and fill it with "[email protected]"
username = driver.find_element(By.NAME, "identifier")
username.send_keys("[email protected]")
username.send_keys(Keys.RETURN)

# Wait a bit for the page to load
time.sleep(50)

# Find the password element and fill it with "asdf1234" and bang! here it
# denies me doing it with the block because Google classifies me as suspicious.
password = driver.find_element(By.NAME, "password")
password.send_keys("asdf1234")
password.send_keys(Keys.RETURN)

# Wait a bit for the page to load
driver.implicitly_wait(5)

# Go to the Google search page
driver.get("https://www.google.com")

# Find the search element and search for "pizza"!!
search_field = driver.find_element(By.NAME, "q")
search_field.send_keys("pizza")
search_field.send_keys(Keys.RETURN)

你知道怎么解决吗?

我尝试了不同的策略,例如从配置文件开始或临时复制谷歌在 .config/google-chrome/ 中的配置文件并为此使用它(它会产生问题,我不推荐它)并且仍然无法登录

有人可以向我解释如何让它工作吗?

authentication selenium-webdriver google-signin python-3.10
© www.soinside.com 2019 - 2024. All rights reserved.