【发布时间】:2018-05-30 23:08:25
【问题描述】:
我编写了一个基本脚本,它尝试使用 Selenium(webdriver) 打开一个网站。
这是我的脚本:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://google.com")
driver.quit()
当我启动上面的脚本时,Firefox 浏览器会弹出,但是它仍然是空白的并且它没有导航到提到的网站(在这种情况下是谷歌)?我确实在终端屏幕上收到错误:
Traceback(最近一次调用最后一次):文件“test.py”,第 10 行,在 驱动程序= webdriver.Firefox()文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py”, 第 158 行,在 init 中 keep_alive=True) 文件 "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", 第 154 行,在 init 中 self.start_session(desired_capabilities,browser_profile)文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”, 第 243 行,在 start_session 中 response = self.execute(Command.NEW_SESSION,参数)文件“/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py”, 第 311 行,在执行中 self.error_handler.check_response(response) 文件 "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", 第 237 行,在 check_response 中 引发异常类(消息,屏幕,堆栈跟踪)selenium.common.exceptions.WebDriverException:消息:连接 拒绝
这里是 geckodriver 日志文件内容:
1513507080726 geckodriver INFO geckodriver 0.19.1 1513507080735 geckodriver INFO 监听 127.0.0.1:47815 1513507081261 mozrunner::runner INFO 运行命令: “/usr/bin/firefox” “-marionette” “-profile” “/tmp/rust_mozprofile.IaZFxa8B0Ir8” 1513507085202 Marionette ERROR 启动服务器时出错:[异常... "组件返回故障码:0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]" nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)”位置:“JS框架:: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95" data: no] [Exception... "组件返回故障码:0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE) [nsIServerSocket.initSpecialConnection]" nsresult: "0x804b0036 (NS_ERROR_SOCKET_ADDRESS_IN_USE)”位置:“JS框架:: chrome://marionette/content/server.js :: MarionetteServer.prototype.start :: line 95" data: no] MarionetteServer.prototype.start@chrome://marionette/content/server.js:95:19 MarionetteComponent.prototype.init@resource://gre/components/marionette.js:217:5 MarionetteComponent.prototype.handle@resource://gre/components/marionette.js:112:5
我不知道这里发生了什么,我似乎不知道如何解决这个错误?你们有什么想法,如何解决这个错误以及是什么原因造成的?
【问题讨论】: