使用 python 和 selenium 进行自动化 Google 登录显示“"此浏览器或应用程序可能不安全“"
问题描述
我尝试使用 Gmail 或任何 Google 服务登录,但它显示以下此浏览器或应用程序可能不安全";留言:
I've tried login with Gmail or any Google services but it shows the following "This browser or app may not be secure" message:
我还尝试在我的账户中启用安全性较低的应用等选项,但没有成功.然后我创建了一个新的谷歌帐户,它对我有用.但不是我的旧账户.
I also tried to do options like enable less secure app in my acc but it didn't work. then I made a new google account and it worked with me. but not with my old acc.
- 我该如何解决这个问题?
- 如何在普通的 chrome 浏览器中打开 selenium,而不是由自动化软件控制的浏览器?
这是我的代码
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
browser = webdriver.Chrome()
browser.get('https://accounts.google.com/servicelogin')
search_form = browser.find_element_by_id("identifierId")
search_form.send_keys('mygmail')
nextButton = browser.find_elements_by_xpath('//*[@id ="identifierNext"]')
search_form.send_keys('password')
nextButton[0].click()
解决方案
首先不要使用chrome和chromedriver.您需要使用 Firefox.(如果未安装)下载并安装 Firefox.使用普通 Firefox 登录 Google.
First of all don't use chrome and chromedriver. You need to use Firefox.(if not installed) Download and install Firefox. Login to Google with normal Firefox.
您需要向 Google 网站表明您不是机器人.你可以使用这样的代码:
You need to show the Google site that you are not a robot. You can use code like this:
from selenium import webdriver
import geckodriver_autoinstaller
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
geckodriver_autoinstaller.install()
profile = webdriver.FirefoxProfile(
'/Users/<user name>/Library/Application Support/Firefox/Profiles/xxxxx.default-release')
profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX
driver = webdriver.Firefox(firefox_profile=profile,
desired_capabilities=desired)
这 可以帮助您找到您的个人资料位置.
This can help you find your profile location.
其实只有一个原因,chromedriver 是谷歌编码的.他们可以很容易地理解它是否是机器人.但是当我们用 Firefox 添加用户数据时,他们无法理解是否存在 bot.
Actually there is only one reason, chromedriver was coded by Google. They can easily understand if it is a bot or not. But when we add user data with Firefox, they cannot understand if there is a bot or not.
你可以这样欺骗 Google.它也对我有用.我非常努力地做到这一点.希望它也能在你身上得到解决.
You can fool Google like this. It worked for me too. I tried very hard to do this. Hope it will be resolved in you too.
相关文章