我們的網絡環境使用代理服務器連接到外部Internet,在IE => Internet選項=>連接=>局域網設置(如「10.212.20.11:8080」)中配置。如何將chomedriver與selenium webdriver的代理一起使用?
現在,我使用selenium webdriver for chrome和IE,但啓用代理服務器後,我無法啓動瀏覽器。
這裏是Python代碼:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe')
以下是錯誤消息(如果禁用IE的 「Internet選項」 的代理,它工作正常):
Traceback (most recent call last):
File "E:\WorkSpace\GitHub\selenium\sandbox\test.py", line 4, in <module>
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe')
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 66, in __init__
self.quit()
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in quit
self.service.stop()
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\service.py", line 97, in stop
url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 406, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 438, in error
result = self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 625, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python27\lib\urllib2.py", line 406, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 444, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized
那麼,如何爲chromedriver設置代理? (IE驅動程序有同樣的問題)。
謝謝Ehsan,但我改變了代碼,錯誤依然存在。
from selenium import webdriver
chrome_option = webdriver.ChromeOptions()
chrome_option.add_argument("--proxy-server=10.213.20.62:80")
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe',
chrome_options=chrome_option)
driver.quit()
解決!只需在IE => Internet選項=>連接=>局域網設置中,添加異常地址爲NOT代理「127.0.0.1」,這個問題就解決了!不管怎麼說,還是要謝謝你!
解決!只需在IE => Internet選項=>連接=>局域網設置中,添加異常地址爲NOT代理「127.0.0.1」,這個問題就解決了!不管怎麼說,還是要謝謝你! –
我在調用'.quit()'時遇到了407錯誤的類似問題,並且您的修復在我的情況中很有幫助。我已經發布了一個[問題和答案](http://stackoverflow.com/questions/22018126/selenium-chromedriver-http-407-on-quit)突出解決方案,包括一個鏈接回到這裏。謝謝! – Tetrinity