我对Google登录有疑问。我想登录到我的帐户,但是Google表示不允许自动化驱动程序登录。
我正在寻找解决方案。是否可以获取普通Firefox / Chrome的cookie并将其加载到ChromeDriver / GeckoDriver中?我认为这可以解决。但是我不确定是否可能。
寻找解决方案..
此错误消息...
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9YYXI2Qi5wbmcifQ==” alt =“此浏览器或应用程序可能不安全”>
...表示WebDriver实例无法认证Browsing Context,即Browser会话。
此错误可能是由于以下各种因素引起的:
在文章"This browser or app may not be secure" error when trying to sign in with Google on desktop apps @Raphael Schaad中提到,如果用户可以使用其他Google帐户登录到同一应用程序,那么问题一定出在特定帐户上。在大多数情况下,可能的原因是,此特定用户帐户配置了Two Factor Authentification。
在文章Less secure apps & your Google Account中提到,如果某个应用或网站不符合google-chrome的security standards,则Google可能会阻止任何尝试从中登录您的帐户的人。安全性较低的应用程序可能使黑客更容易进入您的帐户,因此阻止这些应用程序的登录有助于确保您的帐户安全。
在这些情况下,相应的解决方案是:
您可以在Unable to sign into google with selenium automation because of "This browser or app may not be secure."中找到详细的讨论
但是,为了帮助保护您的帐户,Web浏览器可能不允许您从某些浏览器登录。 Google可能会停止从以下浏览器登录:
在这些情况下,有多种解决方案:
使用支持JavaScript的浏览器:
在Web浏览器]中打开JavaScript:如果使用的是受支持的浏览器,但仍然无法登录,则可能需要打开JavaScript。
如果仍然无法登录,可能是因为您打开了[[AutomationExtension
public class browserAppDemo
{
public static void main(String[] args) throws Exception
{
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.setExperimentalOption("useAutomationExtension", false);
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
WebDriver driver = new ChromeDriver(options);
driver.get("https://accounts.google.com/signin")
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("gashu");
driver.findElement(By.id("identifierNext")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("gashu");
driver.findElement(By.id("passwordNext")).click();
System.out.println(driver.getTitle());
}
}
简短:使用重定向的Google帐户登录Stackoverflow
from selenium import webdriver
from time import sleep
class Google:
def __init__(self, username, password):
self.driver = webdriver.Chrome('./chromedriver')
self.driver.get('https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent%27')
sleep(3)
self.driver.find_element_by_xpath('//*[@id="openid-buttons"]/button[1]').click()
self.driver.find_element_by_xpath('//input[@type="email"]').send_keys(username)
self.driver.find_element_by_xpath('//*[@id="identifierNext"]').click()
sleep(3)
self.driver.find_element_by_xpath('//input[@type="password"]').send_keys(password)
self.driver.find_element_by_xpath('//*[@id="passwordNext"]').click()
sleep(2)
self.driver.get('https://youtube.com')
sleep(5)
username = ''
passwort = ''
Google(username, password)