我在centos上安装了Firefox和Selenium.我正在使用Xvfb和pyvirtualdisplay来打开浏览器.
当我尝试运行selenium webdriver时,我能够尽快打开一个新的显示器
browser = webdriver.Firefox()
我收到错误:
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 134, in __init__
self.service = Service(executable_path, log_path=log_path)
File "/usr/lib/python2.7/site-packages/selenium/webdriver/firefox/service.py", line 45, in __init__
log_file = open(log_path, "a+")
IOError: [Errno 13] Permission denied: 'geckodriver.log'
Run Code Online (Sandbox Code Playgroud)
关于这里出了什么问题的任何线索?
编辑:克服了权限错误,我得到了
Message: 'geckodriver' executable needs to be in PATH
显然,这可能是由于您的Firefox和Selenium之间的不兼容所致。请尝试pip install --upgrade selenium
,如果错误仍然存在,请尝试下载其他版本的Firefox或gecko驱动程序。
关于消息:
'geckodriver' executable needs to be in PATH
Run Code Online (Sandbox Code Playgroud)
您可以在脚本上设置驱动程序的路径:
ff_profile_dir = "/usr/local/selenium/webdriver/firefox"
ff_profile = selenium.webdriver.FirefoxProfile(profile_directory=ff_profile_dir)
driver = selenium.webdriver.Firefox(ff_profile)
Run Code Online (Sandbox Code Playgroud)
或者,根据此答案,您可以在Unix系统上的bash兼容shell上运行:
export PATH=$PATH:/path/to/directory/of/executable/downloaded/in/previous/step
Run Code Online (Sandbox Code Playgroud)
在Windows上,您将需要更新Path系统变量以手动或命令行将完整目录路径添加到可执行geckodriver(不要忘记在将可执行geckodriver添加到系统PATH中生效后重新启动系统)。其原理与Unix相同。
小智 5
我最近在 Windows 10 工作站上遇到了同样的问题。我通过将 service_log_path 显式设置到我知道我有写访问权限的位置来修复它:
browser = webdriver.Firefox(
service_log_path="C:\\Users\\[username]\\AppData\\Local\\Temp\\geckodriver.log"
)
归档时间: |
|
查看次数: |
15591 次 |
最近记录: |