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

时间:2018-06-13 12:43:05

标签: 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'] = {
    "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>

我从下面的参考资料中获取了参考资料 -

https://stackoverflow.com/questions/45949274/setting-proxy-in-selenium-in-python-for-firefox-geckodriver?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

它在FireFox浏览器中工作正常,但我无法在IE浏览器中运行。

1 个答案:

答案 0 :(得分:0)

似乎你非常接近。当您在 Windows OS 时,您需要添加 WebDriver Binary 的扩展名(即 .exe )。此外,将 IEDriverServer 的绝对路径放在单引号(即 '' )中,并将文件分隔符设置为单前斜线(即 \ )前面是原始(即 r )开关,如下所示:

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