Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Chrome 60和Selenium处理所需的身份验证_Python_Google Chrome_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 使用Chrome 60和Selenium处理所需的身份验证

Python 使用Chrome 60和Selenium处理所需的身份验证,python,google-chrome,selenium,selenium-webdriver,selenium-chromedriver,Python,Google Chrome,Selenium,Selenium Webdriver,Selenium Chromedriver,我的问题: https://myuser:mypassword@mysite.com 目前,我需要打开一个网站,在chrome认证窗口中输入用户和密码,但我正在尝试我在互联网上找到的唯一选择,但没有成功 我试过这个: https://myuser:mypassword@mysite.com 但这并不能解决问题,因为在这种格式下,网站不会打开,更不用说使用url中的凭据进行身份验证了 我的堆栈: https://myuser:mypassword@mysite.com Python3+Se

我的问题:

https://myuser:mypassword@mysite.com
目前,我需要打开一个网站,在chrome认证窗口中输入用户和密码,但我正在尝试我在互联网上找到的唯一选择,但没有成功

我试过这个:

https://myuser:mypassword@mysite.com
但这并不能解决问题,因为在这种格式下,网站不会打开,更不用说使用url中的凭据进行身份验证了

我的堆栈:

https://myuser:mypassword@mysite.com
Python3+Selenium 3.3.3+Chrome 60

Idk关于Python,但在c语言中,您可以如下处理它

var alert = driver.SwitchTo().Alert();
alert.SetAuthenticationCredentials("username", "password");
alert.Accept();

你可能需要像我一样使用插件。 这详细说明了我如何解决铬/铬的问题

解决方案: 这是在python 2.7中实现的 但要让它在3.X中工作,应该没有太大的区别

您将需要使用浏览器扩展。 我的解决方案是为chromium构建的,但对于Firefox和edge来说,它应该几乎没有变化

首先您的浏览器需要2个API:

  • webRequest.onAuthRequired
    -&
  • runtime.nativeMessaging
    -&
虽然这两种浏览器API非常相似,但它们确实有一些显著的差异,比如Chrome的实现缺乏

如果将本机消息传递主机设置为发送格式正确的JSON字符串,则只需轮询一次。这意味着您可以使用对
runtime.sendNativeMessage()
的单个调用,并确保您的凭据是可配置的。双关语

接下来,我们需要看看应该如何处理
webRequest.onAuthRequired
事件

因为我在Chromium中工作,所以我需要使用promise less Chrome API

chrome.webRequest.onAuthRequired.addListener(
  callbackFunctionHere,
  {urls:[targetUrls]},
  ['asyncBlocking'] // --> this line is important, too. Very.
变化: 我将调用我的函数
providedecedentials
,因为我是一个偷东西的高手,并且使用了源代码中的一个示例。寻找异步版本

示例代码从
存储.local
获取凭据

chrome.storage.local.get(null, gotCredentials);
我们不想那样。没有

我们希望通过对
sendNativeMessage
的单个调用获取凭据,因此我们将更改这一行

chrome.runtime.sendNativeMessage(hostName, { text: "Ready" }, gotCredentials);
就这些。认真地只要你的主人表现好,这就是最大的秘密。我甚至不会告诉你我花了多长时间才找到它

链接: 我的问题和有用的链接:

  • -针对Active Directory进行身份验证的解决方法
  • -也有一些功能NM主机的工作代码
  • -一些关于承诺的启发性材料

我的上述图像的可能副本不是警报。这个选择对我来说没有解决