Ahm*_*şli 29 selenium google-chrome selenium-chromedriver selenium-webdriver geckodriver
我在使用 Google 登录时遇到问题。我想登录我的帐户,但 Google 说不允许自动化驱动程序登录。
我正在寻找解决方案。是否可以获取普通 Firefox/Chrome 的 cookie 并将其加载到 ChromeDriver/GeckoDriver 中?我认为这可以是一个解决方案。但我不确定这是否可能..
正在寻找解决方案...
另外,我想添加一个快速解决方案。我通过使用我的旧验证帐户之一解决了这个问题。这对你来说是一个快速的解决方案。
Duk*_*uke 10
我遇到了同样的问题并找到了解决方案。我在用
1) 视窗 10 专业版
2) 铬版 83.0.4103.97 (Official Build) (64-bit)
3)硒ChromeDriver 83.0.4103.39
一些打开谷歌页面的简单 C# 代码
var options = new ChromeOptions();
options.addArguments(@"user-data-dir=c:\Users\{username}\AppData\Local\Google\Chrome\User Data\");
IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver();
driver = new ChromeDriver(Directory.GetCurrentDirectory(), options);
driver.Url = "https://accounts.google.com/";
Console.ReadKey();
Run Code Online (Sandbox Code Playgroud)
这里的核心问题是你使用selenium驱动时无法登录,但是你可以使用已经登录到谷歌账户的配置文件。
您必须找到您的 Chrome 商店配置文件所在的位置并将其附加到"user-data-dir"选项中。
附注。将 {username} 替换为您的真实帐户名。
在 linux 上,用户配置文件位于"~/.config/google-chrome".
这个错误信息...
\n
...意味着WebDriver实例无法验证浏览上下文(即浏览器)会话)。
\n此错误可能由于以下不同因素而发生:
\n在文章“此浏览器或应用程序可能不安全”中尝试在桌面应用程序上使用 Google 登录时出现错误@Raphael Schaad 提到,如果用户可以使用其他 Google 帐户正常登录同一应用程序,那么问题一定是使用特定帐户。在大多数情况下,可能的原因是,此特定用户帐户配置了双因素身份验证。
\n在不太安全的应用程序和您的 Google 帐户一文中提到,如果某个应用程序或网站不符合google-chrome的安全标准,Google 可能会阻止任何尝试访问该应用程序或网站的人从中登录您的帐户。安全性较低的应用程序可能会让黑客更容易进入您的帐户,因此阻止这些应用程序登录有助于确保您的帐户安全。
\n在这些情况下,相应的解决方案是:
\n\n\n\n
但是,为了帮助保护您的帐户,网络浏览器可能不允许您从某些浏览器登录。Google 可能会停止通过以下浏览器登录:
\n在这些情况下,有多种解决方案:
\n使用支持JavaScript的浏览器:
\n铬合金
\n苹果浏览器
\n火狐浏览器
\n歌剧
\nIE浏览器
\n边缘
\n在Web 浏览器中打开 JavaScript:如果您\xe2\x80\x99 使用受支持的浏览器,并且仍然无法\xe2\x80\x99 登录,则可能需要打开 JavaScript。
\n如果您仍然可以\xe2\x80\x99t 登录,可能是因为您的AutomationExtension /不安全/不受支持扩展,并且您可能需要按以下方式关闭:
\n public class browserAppDemo \n {\n public static void main(String[] args) throws Exception \n {\n System.setProperty("webdriver.chrome.driver", "C:\\\\Utility\\\\BrowserDrivers\\\\chromedriver.exe");\n ChromeOptions options = new ChromeOptions();\n options.addArguments("start-maximized");\n options.setExperimentalOption("useAutomationExtension", false);\n options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));\n WebDriver driver = new ChromeDriver(options); \n driver.get("https://accounts.google.com/signin")\n new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id=\'identifierId\']"))).sendKeys("gashu");\n driver.findElement(By.id("identifierNext")).click();\n new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name=\'password\']"))).sendKeys("gashu");\n driver.findElement(By.id("passwordNext")).click();\n System.out.println(driver.getTitle());\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n最后,某些旧的浏览器版本可能不受支持,因此请确保:
\n如果您有要访问的特定 Google 帐户,请使用它创建 chrome 配置文件,然后在使用 selenium 时加载 chrome 配置文件:
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/{userName}/AppData/Local/Google/Chrome/User Data/Profile {#}/")
driver = webdriver.Chrome("C:/bin/chromedriver.exe", chrome_options=options)
Run Code Online (Sandbox Code Playgroud)
Windows:
上面文件路径中的配置文件 {#} 会有所不同,因此我建议检查用户数据文件夹内您要使用的配置文件。例如,如果您当前只有 1 个 chrome 帐户,则用户数据中将没有配置文件目录(诉诸“默认”目录),但如果您创建第二个 chrome 帐户,则用户数据中将有一个“配置文件 1”目录。
请注意,您应该创建一个新的 google chrome 配置文件以与 selenium 一起使用,因为尝试使用已在使用的 chrome 配置文件(在另一个 chrome 窗口中打开)将导致错误。
Mac:此解决方案在 Mac 上可能有效,也可能无效,但要找到 chrome 帐户文件夹/文件路径,请按照@bfhaha
留下的评论中的说明进行操作
小智 5
一种适合我的解决方案:https : //stackoverflow.com/a/60328992/12939291或https://www.youtube.com/watch?v=HkgDRRWrZKg
简短:Stackoverflow Login with Google Account with Redirect
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32097 次 |
| 最近记录: |