Selenium + Python + Internet Explorer + Фирменный прокси + PAC-файл + Учетные данные - PullRequest
0 голосов
/ 17 мая 2018

Я использую 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 голосов
/ 17 мая 2018

Если вы используете Python 2.7, вы можете использовать следующий код, чтобы отключить настройку прокси в браузере.

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