我一直在尝试为我的selenium webdriver实现代理。不知道我的代码有什么问题。有什么想法吗?
import os
from selenium import webdriver
def open_browser():
chromeUrl= "C:/Users/Drivers/chromedriver.exe"
firefoxUrl= "C:/Users/Drivers/geckodriver.exe"
edgeUrl="C:/Users/Drivers/MicrosoftWebDriver.exe"
print("Starting opening web browser")
try:
f= open('saved/proxy.txt','r')
proxy_ip = f.read()
f.close()
PROXY= proxy_ip
print("I have download a proxy: " + PROXY)
if len(proxy_ip) <= 1:
print("No Proxy will be used...")
driver = webdriver.Firefox(executable_path= firefoxUrl)
else:
webdriver.DesiredCapabilities.Edge['proxy'] = {
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"noProxy":None,
"proxyType":"MANUAL",
"class":"org.openqa.selenium.Proxy",
"autodetect":False}
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.Edge(EdgeUrl))
except:
os.system("python proxy_request.py")
print("Warning: No proxy")
driver = webdriver.Edge(executable_path= "C:/Users/Drivers/MicrosoftWebDriver.exe")
driver.implicitly_wait(10)
driver.set_page_load_timeout(300)
return driver
driver = open_browser()
url = 'htttp://www.google.com'
driver.get(url)
我无法解决这个问题。官方webdriver文档中的一半代码,虽然我找不到EDGE。