本文的目的是介绍使用Python的Selenium-Geckodriver可执行文件必须位于PATH中的详细情况,特别关注python执行可执行文件的相关信息。我们将通过专业的研究、有关数据的分析等多
本文的目的是介绍使用Python的Selenium-Geckodriver可执行文件必须位于PATH中的详细情况,特别关注python执行可执行文件的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解使用Python的Selenium-Geckodriver可执行文件必须位于PATH中的机会,同时也不会遗漏关于Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中、NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'的知识。
本文目录一览:- 使用Python的Selenium-Geckodriver可执行文件必须位于PATH中(python执行可执行文件)
- Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集
- IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log
- Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中
- NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'
使用Python的Selenium-Geckodriver可执行文件必须位于PATH中(python执行可执行文件)
我正在使用IDLE,并且已经安装了selenium模块和Firefox
浏览器。每当我尝试运行webdrive
r函数时,都会得到以下信息:
from selenium import webdriverbrowser = webdriver.Firefox()
例外:
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0DA1080>>Traceback (most recent call last): File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__ self.stop() File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop if self.process is None:AttributeError: ''Service'' object has no attribute ''process''Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x00000249C0E08128>>Traceback (most recent call last): File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__ self.stop() File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop if self.process is None:AttributeError: ''Service'' object has no attribute ''process''Traceback (most recent call last): File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start stdout=self.log_file, stderr=self.log_file) File "C:\Python\Python35\lib\subprocess.py", line 947, in __init__ restore_signals, start_new_session) File "C:\Python\Python35\lib\subprocess.py", line 1224, in _execute_child startupinfo)FileNotFoundError: [WinError 2] The system cannot find the file specifiedDuring handling of the above exception, another exception occurred:Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> browser = webdriver.Firefox() File "C:\Python\Python35\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__ self.service.start() File "C:\Python\Python35\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start os.path.basename(self.path), self.start_error_message)selenium.common.exceptions.WebDriverException: Message: ''geckodriver'' executable needs to be in PATH.
我想我需要设置路径,geckodriver但不确定如何设置,所以谁能告诉我该怎么做?
答案1
小编典典selenium.common.exceptions.WebDriverException
:消息:“ geckodriver”
可执行文件必须位于PATH中。
首先,你需要从此处下载最新的可执行geckodriver,以使用硒运行最新的Firefox
。
实际上,Selenium
客户端绑定试图geckodriver
从系统中找到可执行文件PATH。你将需要将包含可执行文件的目录添加到系统路径。
在Unix系统上,如果使用的是与bash兼容的shell,则可以执行以下操作将其附加到系统的搜索路径中:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
在Windows上,你将需要更新Path系统变量以 手动或命令行将完整目录路径添加到可执行geckodriver (不要忘记在将可执行geckodriver添加到系统PATH中生效后重新启动系统)。其原理与Unix相同。
现在,你可以按照以下步骤运行代码:-
from selenium import webdriverbrowser = webdriver.Firefox()
selenium.common.exceptions.WebDriverException:
消息:预期的浏览器二进制位置,但无法在默认位置找到二进制位置,未提供’moz:firefoxOptions.binary’功能,并且命令行上未设置二进制标志
异常清楚地表明你在Selenium试图查找Firefox并从默认位置启动时在其他位置安装了Firefox,但找不到。你需要提供明确安装了firefox的二进制位置才能启动firefox,如下所示:
from selenium import webdriverfrom selenium.webdriver.firefox.firefox_binary import FirefoxBinarybinary = FirefoxBinary(''path/to/installed firefox binary'')browser = webdriver.Firefox(firefox_binary=binary)
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?
这些错误为我们提供了一些有关发生了什么错误的提示,如下所示:
[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_path
和log_path=log_path
如下:
if capabilities.get("marionette"):
capabilities.pop("marionette")
self.service = Service(executable_path, log_path=log_path)
self.service.start()
您的程序在这里出错,因为与 key *
[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 倾向于在 当前工作目录中
自行创建文件,并且在缺少所需 情况下,它会出错,并显示以下消息:
解
首要的一点是检查所使用的二进制文件之间的兼容性。
- 确保您使用的是 , 和 _ _
一个解决方案是:
-
初始化 GeckoDriver 与所需的参数
executable_path
和log_path
与 有效的值(CHMOD 777geckodriver.log
),如下所示:def get_index(api_key): if str(api_key)!=the_api_key: return 401 base_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_source return html
-
如果您打算
geckodriver.log
在 Project Workspace中 创建,请确保所需的权限(chmod 777Project Workspace
)如下:def get_index(api_key): if str(api_key)!=the_api_key: return 401 base_url = ''www.google.com'' browser = webdriver.Firefox(executable_path=''/usr/local/bin/geckodriver'') browser.get(base_url) html = browser.page_source return html
解决方法
通过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/
Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中
我是编程的新手,大约2个月前开始使用Python,现在正在研究Sweigart的《用Python文本自动完成无聊的事情》。我正在使用Spyder
3,并且已经安装了selenium模块和Firefox浏览器。我在python文件中使用了以下代码
from selenium import webdriver
browser = 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困难。
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
今天关于使用Python的Selenium-Geckodriver可执行文件必须位于PATH中和python执行可执行文件的介绍到此结束,谢谢您的阅读,有关Centos7上的Python Selenium / Geckodriver无法启动:无法找到匹配的功能集、IOError:[Errno 13]权限被拒绝:运行Python / Selenium时'geckodriver.log、Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中、NotADirectoryError:[Errno 20]不是目录:使用Python3的GeckoDrriver Firefox和Selenium的'/home / ghost / automation / pwd / geckodriver'等更多相关知识的信息可以在本站进行查询。
本文标签: