繁体   English   中英

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

[英]Selenium + Python + Internet Explorer + Firm Proxy + PAC file + 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>

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM