Python的Selenium设置路径到Firefox的个人资料(Ubuntu的)

我已经使用python&Selenium设置了在Ubuntu OS中新创建的Firefox配置文件的路径。 但是当我运行Python脚本时,我收到一个错误

OSError: [Errno 13] Permission denied

我已将文件的权限更改为755,并且仍然收到错误并尝试了sudo。

sudo chmod 775 /home/student/.mozilla/firefox/gwi6uqpe.Default User2/

这是我的python脚本的开始: -

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.by import By
import sys, time
import time

binary = FirefoxBinary('/home/student/.mozilla/firefox/gwi6uqpe.Default User2')
browser = webdriver.Firefox(firefox_binary=binary)

这是错误信息。

Traceback (most recent call last):

文件“default2.py”,第9行,在浏览器中= webdriver.Firefox(firefox_binary = binary)文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py”,行78,in init self.binary,timeout)文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py”,第51行,在init中 self.binary.launch_browser(self .profile,timeout = timeout)文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py”,行67,位于launch_browser self._start_from_profile_path(self.profile.path)文件“/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py”,第90行,位于_start_from_profile_path env = self._firefox_env)文件“/usr/lib/python2.7/ subprocess.py“,第710行,在初始化 errread中,errwrite)文件”/usr/lib/python2.7/subprocess.py“,第1327行,在_execute_child中引发child_exception OSError:[Errno 13] Permission denied

我该如何解决这个问题。


在我的机器上,〜/ .mozilla / firefox和它的子目录拥有user:usergroup 700权限。 你的脚本是由学生用户执行的吗? 否则,它将被拒绝。 作为一个实验,你可以尝试给.mozilla / firefox和.mozilla / firefox / profiles 766权限。 我不会运行这样的生产环境,但可以创建一个具有权限的组,并将其他用户添加到该组。

编辑:FirefoxBinary不是用来指定配置文件。 改用FirefoxProfile:

profile = FirefoxProfile('/home/student/.mozilla/firefox/gwi6uqpe.Default')
browser = webdriver.Firefox(firefox_profile=profile)

   baseurl = "https://www.google.co.in/"
   driver = webdriver.Firefox(executable_path='/usr/local/bin/geckodriver')
   driver.maximize_window()
   driver.get(baseurl)
链接地址: http://www.djcxy.com/p/62751.html

上一篇: Python Selenium setting path to firefox profile (ubuntu)

下一篇: Calling a Selenium Python Script from PHP