在python中为IE浏览器设置selenium代理

在python中为IE浏览器设置selenium代理,python,selenium,internet-explorer,selenium-webdriver,iedriverserver,Python,Selenium,Internet Explorer,Selenium Webdriver,Iedriverserver,我的问题是关于在IE浏览器的python(3.6)中的selenium编码中设置代理 from selenium import webdriver PROXY = "94.56.171.137" PORT = 8080 base_url = "https://google.com" desired_capability = webdriver.DesiredCapabilities.INTERNETEXPLORER desired_capability['proxy'] = { "

我的问题是关于在IE浏览器的python(3.6)中的selenium编码中设置代理

from selenium import webdriver

PROXY = "94.56.171.137"
PORT = 8080

base_url = "https://google.com"

desired_capability = webdriver.DesiredCapabilities.INTERNETEXPLORER
desired_capability['proxy'] = {
    "proxyType": "manual",
    "httpProxy": PROXY,
    "httpProxyPort": PORT,
    "ftpProxy": PROXY,
    "ftpProxyPort": PORT,
    "sslProxy": PROXY,
    "sslProxyPort": PORT,
    "class":"org.openqa.selenium.Proxy",
}

driver = webdriver.Ie(executable_path='C:\\tmp\\IEDriverServer',capabilities=desired_capability)
driver.get(base_url)
我收到下面的错误消息-

<p>The following error was encountered while trying to retrieve the URL: <a href="http://127.0.0.1:54684/session">http://127.0.0.1:54684/session</a></p>

它在FireFox浏览器中运行良好,但我无法在IE浏览器中运行。

看来您已经非常接近了。在Windows操作系统上,您需要添加WebDriver二进制文件的扩展名(即
.exe
)。此外,将IEDriverServer的绝对路径放在单引号内(即
'
),并将文件分隔符放在raw(即
)开关前面的单正斜杠中,如下所示:

from selenium import webdriver

PROXY = "94.56.171.137"
PORT = 8080

base_url = "https://google.com"

desired_capability = webdriver.DesiredCapabilities.INTERNETEXPLORER
desired_capability['proxy'] = {
    "proxyType": "manual",
    "httpProxy": PROXY,
    "httpProxyPort": PORT,
    "ftpProxy": PROXY,
    "ftpProxyPort": PORT,
    "sslProxy": PROXY,
    "sslProxyPort": PORT,
    "class":"org.openqa.selenium.Proxy",
}

driver = webdriver.Ie(executable_path='C:\\tmp\\IEDriverServer',capabilities=desired_capability)
driver.get(base_url)
driver = webdriver.Ie(executable_path=r'C:\tmp\IEDriverServer.exe', capabilities=desired_capability)