Selenium + Python + Internet Explorer +公司代理+ PAC文件+凭据

时间:2018-05-17 07:52:53

标签: python selenium internet-explorer proxy credentials

我正在使用Selenium + Python来浏览互联网。 不幸的是,它不适用于我的公司的Internet Explorer(但它适用于Chrome),当然因为有一个代理,需要使用PAC文件浏览我公司的互联网。

这是我的代码:

from selenium import webdriver
from selenium.webdriver.common.proxy import ProxyType
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.ie.webdriver import WebDriver as Ie


ie_path=...
url_of_the_pac_file=...

caps = DesiredCapabilities.INTERNETEXPLORER
caps["proxy"] = {"proxyType": "pac","proxyAutoconfigUrl": url_of_the_pac_file}


driver=Ie(executable_path=ie_path,capabilities=caps,port=8080)
driver.get("http://www.google.com")

每次运行此代码时,都会收到以下消息:

Traceback (most recent call last):
  File "C:\Users\TEST\Desktop\demo\demo_ie.py", line 34, in <module>
    driver=Ie(executable_path=ie_path,capabilities=caps,port=8080) #, capabilities=caps, port=0, timeout=30, host=None, log_level=None, log_file=log_path, ie_options=None)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\ie\webdriver.py", line 82, in __init__
    desired_capabilities=capabilities)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute
    self.error_handler.check_response(response)
  File "C:\Anaconda3_3.4_32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: <html>
<head>
<title>Access Denied - Web Proxy</title>
<meta name="author" content="Information">
<meta name="description" content="Default exception - Web Proxy">
</head>
<body>
<center>
<font face="Arial, Helvetica, sans-serif" size="2" color="black">
<p>
<p><big><b>Access Denied (authentication_failed)</b></big>
<p>Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.
<p>If you have any questions, please contact your local support and provide information of section "Support information".
<br/>
<HR>
<p>
<TABLE border=0 cellPadding=1 style="font-family:Verdana; font-size:11px;">
<CAPTION><big><b>Support information</b></big></CAPTION>
<TR><TD>Action:</TD><TD>Default exception (authentication_failed) - Web Proxy</TD></TR>
<TR><TD>Proxy:</TD><TD>SXB9-NETpxGTW-W3</TD></TR>
<TR><TD>Client IP Address:</TD><TD>10.72.84.12</TD></TR>
<TR><TD>User-ID (realm):</TD><TD> (Domain_CDM_ProfileBasedAuth)</TD></TR>
<TR><TD>User LDAP groups:</TD><TD></TD></TR>
<TR><TD>Full URL:</TD><TD>http://127.0.0.1:8080/session</TD></TR>
<TR><TD>Method:</TD><TD>POST</TD></TR>
<TR><TD>Date:</TD><TD>2018-05-17 07:37:41</TD></TR>
<TR><TD>User agent:</TD><TD>Python http auth</TD></TR>
<TR><TD>Categories BC:</TD><TD> none</TD></TR>
<TR><TD>Categories ALL:</TD><TD> none</TD></TR>
</TABLE>
<p>
</center>
</font>
</body>
</html>

这似乎需要我的证书,但我不知道该怎么做。 谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

如果您使用的是python 2.7,则可以使用以下代码在浏览器上禁用代理设置。

relation, total_size_pretty, total_size, recoverable_space_pretty, recoverable_space