我正在使用Selenium的自定义配置文件,我将其命名为selenium并进行设置,以便在启动新的Firefox时不会询问代理密码。
然后在Python 2.7中,我正在使用这个脚本。
from selenium import webdriver
myprofile = webdriver.FirefoxProfile("C:\Users\MeMeAndMe\AppData\Roaming\Mozilla\Firefox\Profiles\yxc5xxxm.selenium")
browser = webdriver.Firefox(firefox_profile=myprofile) # Get local session of firefox
最后一行给出401,但浏览器绝对没问题。如果我在浏览器中输入www.google.com,它将在页面上没有任何弹出窗口。因此,我无法将新的浏览器实例分配给browser
。
有人遇到过类似的东西吗?
Traceback (most recent call last):
File "D:\SRC\NuffieldLogger\NuffieldLogger\nuffield_selenium.py", line 9, in <module>
browser = webdriver.Firefox(firefox_profile=myprofile) # Get local session of firefox
File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 61, in __init__
desired_capabilities=capabilities)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 72, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 114, in start_session
'desiredCapabilities': desired_capabilities,
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 136, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: '<HTML><HEAD><TITLE>pxgsc1 - Access Denied - 401</TITLE></HEAD><BODY><IMG src="http://ieconfig.sig.echonet.uk.net.intra/images/logo-en.png" alt="MicroTosh"><p><FONT color=red face=Verdana size=4> Access Denied</font><br>\r\n<FONT color=black face=Verdana size=2><br>Your credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.<br><br>For access please contact Client Services.</p>\r\n<p><B>Technical Data</B><br><ul><li>URL: http://127.0.0.1:63286/hub/session<li>IP: 10.2.15.231<li>Proxy: pxgsc1<li>Category: none<li>Error: 401 - authentication_failed</ul>This is typically caused by an incorrect username and/or password, but could also be caused by network problems.</FONT></p></BODY></HTML>\r\n'
答案 0 :(得分:1)
401的http://ieconfig.sig.echonet.uk.net.intra
部分是一个死的赠品,它是代理问题。
根据WebDriver doc ...
您可以通过
设置代理from selenium import webdriver
PROXY = "localhost:8080"
webdriver.DesiredCapabilities.INTERNETEXPLORER['proxy'] = {
"httpProxy":PROXY,
"ftpProxy":PROXY,
"sslProxy":PROXY,
"noProxy":None,
"proxyType":"MANUAL",
"class":"org.openqa.selenium.Proxy",
"autodetect":False
}
# you have to use remote, otherwise you'll have to code it yourself in python to
# dynamically changing the system proxy preferences
driver = webdriver.Remote("http://localhost:4444/wd/hub", webdriver.DesiredCapabilities.INTERNETEXPLORER)