GVKun编程网logo

Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中(python执行可执行文件)

25

针对Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中和python执行可执行文件这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Centos7上

针对Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中python执行可执行文件这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、MAC上的selenium,消息:“ chromedriver”可执行文件可能具有错误的权限、NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'等相关知识,希望可以帮助到你。

本文目录一览:

Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中(python执行可执行文件)

Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中(python执行可执行文件)

我是编程的新手,大约2个月前开始使用Python,现在正在研究Sweigart的《用Python文本自动完成无聊的事情》。我正在使用Spyder
3,并且已经安装了selenium模块和Firefox浏览器。我在python文件中使用了以下代码

from selenium import webdriverbrowser = webdriver.Firefox()browser.get(''http://inventwithpython.com'')

我收到此错误:

Message: ''geckodriver'' executable needs to be in PATH.

除了进入终端并使用进行安装外,我还下载了geckodriver.exe。

brew install geckodriver

奇怪的是,如果我进入终端并输入“
python”,然后将代码放入,它可以工作,但是当我在Spyder中运行文件时却不能。我需要将geckodriver.exe文件放在哪里才能正常工作?我尝试将其放在各种文件夹中(与python文件相同的文件夹,与webdriver文件相同的文件夹,在用户bin中,依此类推),但出现相同的错误

我看过类似的问题,但似乎找不到有效的方法。我也尝试过使用Chrome,但使用chromedriver却遇到了相同的错误。

which geckodriver

产量 /usr/local/bin/geckodriver

我也在Mac上,因此文件路径比Windows困难。

答案1

小编典典

已解决:我将geckodriver exe放在/ Users / sethkillian / anaconda /
bin中,现在可以从Spyder正常使用了。谢谢您的帮助!

Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集

Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集

如何解决Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集?

  • Centos7
  • Firefox 68.5.0esr(64位)
  • Python 3.6.8
  • 硒3.141.0
  • Geckodriver 0.27.0(Linux 64位)

我正在尝试使用Selenium自动化对网站的一些测试,但是会收到此异常:

Traceback (most recent call last):
  File "guitester.py",line 22,in <module>
    browser = webdriver.Firefox(executable_path=gecko_path,firefox_binary=binary)
  File "/home/ian/python3_venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py",line 174,in __init__
    keep_alive=True)
  File "/home/ian/python3_venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 157,in __init__
    self.start_session(capabilities,browser_profile)
  File "/home/ian/python3_venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 252,in start_session
    response = self.execute(Command.NEW_SESSION,parameters)
  File "/home/ian/python3_venv/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py",line 321,in execute
    self.error_handler.check_response(response)
  File "/home/ian/python3_venv/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py",line 242,in check_response
    raise exception_class(message,screen,stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

我的PATH中有geckodriver,并仔细检查了所有相关软件的版本。我的代码是基本的:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

gecko_path = ''/usr/local/bin/geckodriver''
binary = FirefoxBinary(''/usr/bin/firefox'')
browser = webdriver.Firefox(executable_path=gecko_path,firefox_binary=binary)

我已经尝试过使用webdriver.Firefox()包含和不包含的参数,并且两种方法都得到相同的异常。其他帖子提到了不正确的版本,但是我的研究表明我使用的所有内容都应该兼容。我正在使用python虚拟环境。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log

IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log

通过Flask / Python运行Selenium时收到以下错误

browser = webdriver.Firefox()[Wed Mar 07 03:02:27.719608 2018] [:error] [pid 21555] [client 108.162.250.6:36139]   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__[Wed Mar 07 03:02:27.719611 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_path=log_path)[Wed Mar 07 03:02:27.719614 2018] [:error] [pid 21555] [client 108.162.250.6:36139]   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/service.py", line 44, in __init__[Wed Mar 07 03:02:27.719617 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None[Wed Mar 07 03:02:27.719620 2018] [:error] [pid 21555] [client 108.162.250.6:36139] IOError: [Errno 13] Permission denied: ''geckodriver.log''

该功能是

def get_index(api_key):    if str(api_key)!=the_api_key:        return 401    base_url = ''www.google.com''    browser = webdriver.Firefox()    browser.get(base_url)    html = browser.page_source    return html

如果直接进入应用程序目录并运行脚本(python run.py),则不会收到该错误。

基于此,通过Flask运行时,日志文件似乎不可写,但该文件应位于何处?

geckdriver 可执行文件安装在 /usr/local/bin/

答案1

小编典典

这些错误为我们提供了一些有关发生了什么错误的提示,如下所示:

[Wed Mar 07 03:02:27.719608 2018] [:error] [pid 21555] [client 108.162.250.6:36139]   File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 151, in __init__[Wed Mar 07 03:02:27.719611 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_path=log_path)

按照源代码中的 GeckoDriver 得到了两个默认参数发起executable_pathlog_path=log_path如下:

    if capabilities.get("marionette"):        capabilities.pop("marionette")        self.service = Service(executable_path, log_path=log_path)        self.service.start()

您的程序在这里出错,因为与 key log_path* 对应的 Value log_path
log_file)是不可编辑的(附加的),最终失败了: __
*

[Wed Mar 07 03:02:27.719617 2018] [:error] [pid 21555] [client 108.162.250.6:36139]     log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None[Wed Mar 07 03:02:27.719620 2018] [:error] [pid 21555] [client 108.162.250.6:36139] IOError: [Errno 13] Permission denied: ''geckodriver.log''

根据源代码,默认情况下启动 GeckoDriver服务 ,如下所示:

class Service(service.Service):“”“管理GeckoDriver的启动和停止的对象。”“”

def __init__(self, executable_path, port=0, service_args=None,             log_path="geckodriver.log", env=None):    """Creates a new instance of the GeckoDriver remote service proxy.    GeckoDriver provides a HTTP interface speaking the W3C WebDriver    protocol to Marionette.    :param log_path: Optional path for the GeckoDriver to log to.        Defaults to _geckodriver.log_ in the current working directory.    """    log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None

这意味着如果您没有通过geckodriver.log程序显式传递位置,则 GeckoDriver 倾向于在 当前工作目录中
自行创建文件,并且在缺少所需 权限的 情况下,它会出错,并显示以下消息: Permission denied:’geckodriver.log

首要的一点是检查所使用的二进制文件之间的兼容性。

  • 确保您使用的是 Selenium-Python Client v3.10.0GeckoDriver v0.19.1 和 _ Firefox Quantum v58.0.2_

一个解决方案是:

  • 初始化 GeckoDriver 与所需的参数executable_pathlog_path有效的值(CHMOD 777geckodriver.log,如下所示:

    def get_index(api_key):if str(api_key)!=the_api_key:return 401base_url = ''www.google.com''browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver", log_path="/path/to/geckodriver.log")browser.get(base_url)html = browser.page_sourcereturn html
  • 如果您打算geckodriver.logProject Workspace中 创建,请确保所需的权限(chmod 777 Project Workspace)如下:

    def get_index(api_key):if str(api_key)!=the_api_key:return 401base_url = ''www.google.com''browser = webdriver.Firefox(executable_path=''/usr/local/bin/geckodriver'')browser.get(base_url)html = browser.page_sourcereturn html

MAC上的selenium,消息:“ chromedriver”可执行文件可能具有错误的权限

MAC上的selenium,消息:“ chromedriver”可执行文件可能具有错误的权限

我只是在尝试使用selenium在Mac上做一些非常基础的事情,甚至无法打开网页。我收到一个错误:

Traceback (most recent call last):  File "/Users/godsinred/Desktop/InstagramLiker/GmailAccountGenerator.py", line 10, in <module>    driver = webdriver.Chrome()  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__    self.service.start()  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 88, in start    os.path.basename(self.path), self.start_error_message)selenium.common.exceptions.WebDriverException: Message: ''chromedriver'' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

这是我的代码如下:

from selenium import webdriverimport timelink = "https://accounts.google.com"driver = webdriver.Chrome()driver.get(link)time.sleep(5)driver.quit()

答案1

小编典典

错误说明了一切:

selenium.common.exceptions.WebDriverException: Message: ''chromedriver'' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

该错误明确提到正在检测到的 chromedriver 具有错误的权限。


  • 从ChromeDriver-WebDriver for Chrome下载最新的 chromedriver 二进制文件并将其保存在系统中。
  • 确保 chromedriver 二进制文件具有所需的权限。
  • 在启动 WebDriverWebClient时, 将参数 execute_path连同chromedriver 二进制 文件 的绝对路径一起传递,如下所示: __

    from selenium import webdriver

    link = "https://accounts.google.com“
    driver = webdriver.Chrome(executable_path=’/path/to/chromedriver’)
    driver.get(link)


参考

您可以在以下位置找到详细的相关讨论:

  • “ Webdrivers”可执行文件可能具有错误的权限。请参阅https://sites.google.com/a/chromium.org/chromedriver/home

NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'

NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'

如何解决NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的''/home / ghost / automation / pwd / geckodriver''?

虽然有工作 GeckoDriver火狐 ,你需要使用 密钥 executable_path 设置到 绝对路径 中的 GeckoDriver 单引号,即''...''用斜杠即/作为 路径分隔符 ,如下所示:

driver = webdriver.Firefox(executable_path=''/home/ghost/automation/pwd/geckodriver'')

解决方法

我正在使用pycharm和我的pythn

版本3.6.7点9.0.1

和selenium版本selenium-3.141.0 urllib3-1.24.1

我使用此命令安装selenium

pip3 install selenium

然后我这样编码

from selenium import webdriver

driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")

driver.set_page_load_timeout(30)
driver.get("https://www.google.com/")
driver.maximize_window()
driver.implicitly_wait(120)
driver.get_screenshot_as_file("google.png")
driver.quit()

当我运行这个时,我得到这个错误

/home/ghost/PycharmProjects/try/venv/bin/python /home/ghost/PycharmProjects/try/open/testcas1.py
Traceback (most recent call last):
  File "/home/ghost/PycharmProjects/try/open/testcas1.py",line 3,in <module>
    driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
  File "/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py",line 151,in __init__
    firefox_profile = FirefoxProfile(firefox_profile)
  File "/home/ghost/PycharmProjects/try/venv/lib/python3.6/site-packages/selenium/webdriver/firefox/firefox_profile.py",line 80,in __init__
    ignore=shutil.ignore_patterns("parent.lock","lock",".parentlock"))
  File "/usr/lib/python3.6/shutil.py",line 309,in copytree
    names = os.listdir(src)
NotADirectoryError: [Errno 20] Not a directory: ''/home/ghost/automation/pwd/geckodriver''

Process finished with exit code 1

在这一行中 driver = webdriver.Firefox("/home/ghost/automation/pwd/geckodriver")
geckodriver 我的 geckodriver版本的 正确路径 是0.23.0

关于Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中python执行可执行文件的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、MAC上的selenium,消息:“ chromedriver”可执行文件可能具有错误的权限、NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'等相关知识的信息别忘了在本站进行查找喔。

本文标签: