2

我将 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' 
4

1 回答 1

1

401的http://ieconfig.sig.echonet.uk.net.intra一部分是一个死的赠品,它是一个代理问题。

根据WebDriver 文档...

您可以通过以下方式设置代理

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)
于 2013-09-12T22:06:37.387 回答