【发布时间】:2013-05-05 06:36:29
【问题描述】:
我想使用 Selenium Webdriver,但我无法这样做,因为当我运行我的代码时,我得到了以下异常。 我的代码很基础,如下。
from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.google.com.bh")
assert "Google" in driver.title
driver.close()
Exception Message
selenium.common.exceptions.WebDriverException: Message: '<HTML><HEAD>\n<TITLE>Access Denied</TITLE>\n</HEAD>\n<BODY>\n<FONT face="Helvetica">\n<big><strong></strong></big><BR>\n</FONT>\n<blockquote>\n<TABLE border=0 cellPadding=1 width="80%">\n<TR><TD>\n<FONT face="Helvetica">\n<big>Access Denied (authentication_failed)</big>\n<BR>\n<BR>\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica">\nYour credentials could not be authenticated: "Credentials are missing.". You will not be permitted access until your credentials can be verified.\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica">\nThis is typically caused by an incorrect username and/or password, but could also be caused by network problems.\n</FONT>\n</TD></TR>\n<TR><TD>\n<FONT face="Helvetica" SIZE=2>\n<BR>\nFor assistance, contact your network support team.\n</FONT>\n</TD></TR>\n</TABLE>\n</blockquote>\n</FONT>\n</BODY></HTML>\n'
它会打开 Firefox,但之后无法连接到 google 或任何其他本地站点。
例外是driver = webdriver.Firefox()
我在 Google 上四处搜索,并在 SO 上关注了 link。
但不幸的是,我仍然遇到同样的错误。 我无法以 root 用户身份运行。我更改了代理设置并为 localhost 设置了 No Proxy 元素以及链接中提到的内容。
我使用的是 Python 2.7 并且已经安装了 selenium 2.31 版本。
我也试过设置代理。
myProxy = "*********:8080"
proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': 'localhost,127.0.0.1,*.abc'
})
driver = webdriver.Firefox(proxy=proxy)
我还尝试将代理设置为系统的代理,即在上面的代码中,'proxyType': ProxyType.SYSTEM
但它再次给出上述异常消息。 有需要设置用户名和密码的地方吗?
任何帮助将不胜感激!
【问题讨论】:
-
您可以通过更改您的 Firefox 配置文件来做到这一点。检查我的答案。 stackoverflow.com/a/38168865/5409601
标签: selenium python-2.7 webdriver selenium-webdriver