Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在无头raspberry pi上使用firefox运行python selenium_Python_Linux_Selenium_Firefox_Raspberry Pi - Fatal编程技术网

在无头raspberry pi上使用firefox运行python selenium

在无头raspberry pi上使用firefox运行python selenium,python,linux,selenium,firefox,raspberry-pi,Python,Linux,Selenium,Firefox,Raspberry Pi,我正试图让selenium使用firefox开发我的无头覆盆子pi。我在chrome的Windows上运行得很好。以下是我的版本: uname -a Linux megabyte.thompco.com 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux which firefox /usr/bin/firefox firefox --version Mozilla Firefox 52.5.2 ./geck

我正试图让selenium使用firefox开发我的无头覆盆子pi。我在chrome的Windows上运行得很好。以下是我的版本:

uname -a Linux megabyte.thompco.com 4.9.59-v7+ #1047 SMP Sun Oct 29
12:19:23 GMT 2017 armv7l GNU/Linux

which firefox
/usr/bin/firefox

firefox --version
Mozilla Firefox 52.5.2

./geckodriver_32 --version
geckodriver 0.19.1

The source code of this program is available from
testing/geckodriver in https://hg.mozilla.org/mozilla-central.

This program is subject to the terms of the Mozilla Public License 2.0.
You can obtain a copy of the license at https://mozilla.org/MPL/2.0/.
我想我已经有了驱动程序和firefox的兼容版本(这似乎可行):

当我运行以下代码时:

def __init__(self, tag, user_name, password, driver_location, headless):
    logger = logging_utils.get_logger()
    logging_utils.start_function(logger, user_name=user_name)
    self.tag = tag
    self.user_name = user_name
    self.password = password
    self.cards = []
    driver_options = Options()
    driver = None
    try:
        if "chrome" in driver_location.lower():
            if headless:
                driver_options.add_argument("--headless")
            driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver.exe"),
                                      chrome_options=driver_options)
        elif "gecko" in driver_location.lower():
            binary = FirefoxBinary("/usr/bin/firefox")
            driver_options.binary = binary
            profile = webdriver.FirefoxProfile()
            driver_options.profile = profile
            driver_options.set_headless(headless)
            driver = webdriver.Firefox(firefox_binary=binary,
                                       firefox_profile=profile,
                                       executable_path=os.path.abspath(driver_location),
                                       firefox_options=driver_options)
我得到这个错误:

Traceback (most recent call last):

  File "/mnt/usbdrive/python/AmexOfferChecker/amexParser.py", line 105, in __init__
    firefox_options=driver_options)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)

SessionNotCreatedException: Message: Unable to find a matching set of capabilities
  geckodriver_32
  /mnt/usbdrive/python/AmexOfferChecker/geckodriver_32
  Traceback (most recent call last):

  File "/mnt/usbdrive/python/AmexOfferChecker/amexParser.py", line 106, in __init__
    firefox_options=options)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)

WebDriverException: Message: Process unexpectedly closed with status: 1
欢迎提出任何建议

我修改了我的“壁虎”部分,使其看起来像这样:

            options = Options()
            options.add_argument('-headless')
            print driver_location
            print os.path.abspath(driver_location)
            driver = Firefox(executable_path=os.path.abspath(driver_location),
                             firefox_options=options)
            print "Driver has been loaded!"
现在我得到了这个错误:

Traceback (most recent call last):

  File "/mnt/usbdrive/python/AmexOfferChecker/amexParser.py", line 105, in __init__
    firefox_options=driver_options)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)

SessionNotCreatedException: Message: Unable to find a matching set of capabilities
  geckodriver_32
  /mnt/usbdrive/python/AmexOfferChecker/geckodriver_32
  Traceback (most recent call last):

  File "/mnt/usbdrive/python/AmexOfferChecker/amexParser.py", line 106, in __init__
    firefox_options=options)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
    keep_alive=True)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
    self.error_handler.check_response(response)

  File "/home/jordan/.local/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
    raise exception_class(message, screen, stacktrace)

WebDriverException: Message: Process unexpectedly closed with status: 1
我确实看到了这个bug: 在Linux上,尽管headless模式不使用某些库,但您的系统当前需要这些库,因为Firefox链接到它们。有关修复的更多详细信息和进度,请参阅。 我添加了建议的库:

sudo apt-get install libgtk-3-0 libdbus-glib-1-2 xvfb
但我还是得到了同样的例外

我也尝试过同样的错误(注意调试文件已创建,但为空):

终于打开了seleniuim的日志记录(这对任何人都有意义吗?)

2018-01-24 22:51:00078-selenium.webdriver.remote.remote\u连接480-DEBUG-POSThttp://127.0.0.1:45413/session {“功能”:{“alwaysMatch”:{“AcceptSecureCerts”:true,“browserName”:“firefox”,“moz:firefoxOptions”:{“args”:[“headless”]}},“firstMatch”:[{}]},“desiredCapabilities”:{“AcceptSecureCerts”:true,“browserName”:“firefox”、“moz:firefoxOptions”:{“args”:[“headless”]}
2018-01-24 22:51:00944-selenium.webdriver.remote.remote_connection 567-DEBUG-完成请求{“值”:{“错误”:“未知错误”,“消息”:“进程意外关闭,状态为1”,“堆栈跟踪”:"堆栈回溯:\n 0:0x55d797-backtrace::backtrace::trace::hc4bd56a2f176de7e\n 1:0x55d8ff-backtrace::capture::backtrace::new::he3b2a15d39027c46\n 2:0x4b7f4b-webdriver::error::WebDriverError::new::ha0fbd6d1a131b43\n 3:0x4bcb57-geckodriver::木偶网::木偶处理程序::创建连接::hf0532ddb9e1594:0x4a14cb-::运行::h2119c674d7b88193\n 5:0x47fcbf-std::系统公用::回溯::uuu生锈u开始u短回溯::h21d98a9ff86d4c25\n 6:0x4871cf-std::恐慌::try::do call::h5cff0c9b18cfdbba\n 7:0x606237-恐慌解除::u生锈u可能会在/checkout/src/librain/librain/lib.rs:99\n 8:0xE997解除呼叫盒-49413eb1d9d9f1c473\n 9:0x6000d3-alloc::boxed:{{impl}}::在/checkout/src/liballoc/boxed.rs:692\n-std::sys\u common::thread::start\n在/checkout/src/libstd/sys\u common/thread.rs:21\n-std::sys::imp::thread:{impl}}::new::thread_start\n在/checkout/src/libstd/sys/unix/thread.rs:84“}
2018-01-24 22:51:00947-main.main 38-警告-问题(消息:进程意外关闭,状态为1
下面是错误的症结所在(有趣的是,它被报告为调试)。有人有什么建议吗:

2018-01-24 22:51:02,863 - selenium.webdriver.remote.remote_connection 567 -DEBUG - Finished Request 
{"value":
    {"error":"unknown error","message":"Process unexpectedly closed with status: 1","stacktrace":"stack backtrace:
    0:   0x576797 - backtrace::backtrace::trace::hc4bd56a2f176de7e
    1:   0x5768ff - backtrace::capture::Backtrace::new::he3b2a15d39027c46
    2:   0x4d0f4b - webdriver::error::WebDriverError::new::ha0fbd6d1a1131b43
    3:   0x4d5b57 - geckodriver::marionette::MarionetteHandler::create_connection::hf0532ddb9e159684
    4:   0x4ba4cb - <webdriver::server::Dispatcher<T, U>>::run::h2119c674d7b88193
    5:   0x498cbf - std::sys_common::backtrace::__rust_begin_short_backtrace::h21d98a9ff86d4c25
    6:   0x4a01cf - std::panicking::try::do_call::h5cff0c9b18cfdbba
    7:   0x61f237 - panic_unwind::__rust_maybe_catch_panic
    at /checkout/src/libpanic_unwind/lib.rs:99
    8:   0x4b29e7 - <F as alloc::boxed::FnBox<A>>::call_box::h413eb1d9d9f1c473
    9:   0x6190d3 - alloc::boxed::{{impl}}::call_once<(),()>
    at /checkout/src/liballoc/boxed.rs:692
    - std::sys_common::thread::start_thread
    at /checkout/src/libstd/sys_common/thread.rs:21
    - std::sys::imp::thread::{{impl}}::new::thread_start
    at /checkout/src/libstd/sys/unix/thread.rs:84"
    }
}
2018-01-24 22:51:02863-selenium.webdriver.remote.remote\u连接567-DEBUG-Finished请求
{“价值”:
{“错误”:“未知错误”,“消息”:“进程意外关闭,状态为1”,“堆栈跟踪”:“堆栈回溯:
0:0x576797-backtrace::backtrace::trace::hc4bd56a2f176de7e
1:0x5768ff-backtrace::capture::backtrace::new::he3b2a15d39027c46
2:0x4d0f4b-webdriver::错误::WebDriverError::新建::ha0fbd6d1a1131b43
3:0x4d5b57-geckodriver::木偶网::木偶网处理器::创建连接::hf0532ddb9e159684
4:0x4ba4cb-::运行::h2119c674d7b88193
5:0x498cbf-std::sys_common::backtrace::_rust_begin_short_backtrace::h21d98a9ff86d4c25
6:0x4a01cf-std::恐慌::尝试::do_call::h5cff0c9b18cfdbba
7:0x61f237-恐慌\u放松::\u生锈\u可能会抓住\u恐慌
at/checkout/src/libpanic\u unwind/lib.rs:99
8:0x4b29e7-::呼叫盒::h413eb1d9d9f1c473
9:0x6190d3-alloc::boxed::{{impl}}}::调用_一次
at/checkout/src/liballoc/boxed.rs:692
-std::sys\u common::thread::start\u thread
at/checkout/src/libstd/sys_common/thread.rs:21
-std::sys::imp::thread::{{impl}}::new::thread\u start
at/checkout/src/libstd/sys/unix/thread.rs:84“
}
}

最终实现了这一点,但使用了chromedriver和chrome。 您必须首先安装chrome:

sudo apt-get install chromium-browser
接下来从这里下载debian软件包: 解压缩文件“chromedriver”:

代码的其余部分保持不变

        driver_options.add_argument("headless")

很好(“--headless”也可以,我还没有试过)。我当然希望有人在花我这么多时间之前找到它!

您也可以尝试声明DISPLAY变量,它特别适用于远程连接。 在终端上运行此命令:

export DISPLAY=:0.0

您的实现与Mozilla官方指南大不相同。您是否尝试按此处所述进行更改-我进行了建议的更改(如上所示),但收到了不同的错误(如上所示).第二个建议,您希望在raspberry pi上运行它,它有arm cpu,但正如我从您运行32位版本的名称中了解到的,如何尝试运行特定于arm的geckodriver?我意识到它是一个arm处理器(这就是为什么我下载了32位arm版本的gecko驱动程序).正如我一开始提到的,驱动程序在命令行中运行良好:./geckodriverèu 32-b/usr/bin/firefox 1516245181824 geckodriver INFO geckodriver 0.19.1 1516245181881 geckodriver INFO监听127.0.0.1:4444好吧,在geckodriver firefox的某个地方看起来有错误。你能试着设置正确的日志吗?错误消息没有给出任何信息。可能会将firefox更新为最新版本(geckodriver wiki建议55+),应该是:
cp tmp/usr/bin/chromedriver。
因为chromedriver安装在自定义目录中
        driver_options.add_argument("headless")
export DISPLAY=:0.0