在GeckoDriver中加载Firefox时权限被拒绝

时间:2019-04-03 17:13:14

标签: python-3.x selenium docker firefox geckodriver

在python3中运行抓取文件时,出现“ PermissionError:[Errno 13]权限被拒绝:'firefox'”

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')

binary = FirefoxBinary('firefox')
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
driver = webdriver.Firefox(executable_path='geckodriver', options=options, capabilities=cap, firefox_binary=binary)

但是我得到了:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 175, in __init__
    self.binary, timeout)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
    self.binary.launch_browser(self.profile, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 72, in launch_browser
    self._start_from_profile_path(self.profile.path)
  File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 95, in _start_from_profile_path
    env=self._firefox_env)
  File "/usr/local/lib/python3.6/subprocess.py", line 729, in __init__
    restore_signals, start_new_session)
  File "/usr/local/lib/python3.6/subprocess.py", line 1364, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: 'firefox'

所有这些都在DockerImage中

1 个答案:

答案 0 :(得分:0)

我几乎遇到了同样的问题,然后我发现我要发送的路径是到firefox文件夹,而不是程序本身。

尝试

binary = FirefoxBinary('firefox/firefox')