簡體   English   中英

Python Selenium設置Firefox配置文件的路徑(ubuntu)

[英]Python Selenium setting path to firefox profile (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,在初始化 self.binary中,超時)文件“ /usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py”,第51行,在初始化 self.binary.launch_browser(self .profile,超時=超時)文件“ /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行, init errread,errwrite)文件“ /usr/lib/python2.7/subprocess.py”,第1327行,_execute_child中引發child_exception OSError:[Errno 13]權限被拒絕

請問我該如何解決。

在我的機器上,〜/ .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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM