Python Selenium Firefox [Errno 13]权限被拒绝:'geckodriver.log'(Mac OS)

时间:2018-10-11 13:11:45

标签: python python-3.x selenium geckodriver selenium-firefoxdriver

所有人。

编辑(已解决问题):

初始化Firefox时,我必须指定“ service_log_path”的参数,但不使用选项。花了我一天的时间来解决。使我意识到自己的错误的原因是检查了service.py和webdriver.py源代码。最终代码如下:

#!/usr/bin/env python

import os
import sys
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import time

if __name__ == "__main__":
    options = Options()
    options.add_argument('-headless')
    # ~/Library/PythonDenis/geckodriver.log
    # /usr/local/bin/geckodriver.log
    driver = Firefox(executable_path = '/usr/local/bin/geckodriver', service_log_path = '/usr/local/bin/geckodriver.log' ,options = options)
    wait = WebDriverWait(driver, timeout = 10)

问题:

我已经设置了一个“ Python3”脚本,该脚本可以自动执行“ Firefox”中的某些任务并以“无头”模式运行。我目前的目标是使其每天在Mac OS上运行,我尝试使用“启动”工具进行设置。我做了一个看起来像这样的“ plist”:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.yourusername.proverka</string>
    <!-- Specify how to run your program here -->
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/python3</string>
        <string>/Users/Denis/Library/PythonDenis/proverka.py</string>
    </array>
<key>StandardErrorPath</key>
<string>/Users/Denis/Library/PythonDenis/proverka_err.log</string>
<key>StandardOutPath</key>
<string>/Users/Denis/Library/PythonDenis/proverka.log</string>
    <key>StartInterval</key>
    <integer>60</integer><!-- seconds -->
</dict>
</plist>

我得到的错误如下:

Traceback (most recent call last):
  File "/Users/Denis/Library/PythonDenis/proverka.py", line 20, in <module>
    driver = Firefox(executable_path = '/usr/local/bin/geckodriver', options = options)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 163, in __init__
    log_path=service_log_path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/firefox/service.py", line 44, in __init__
    log_file = open(log_path, "a+") if log_path is not None and log_path != "" else None
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'

从我的Python代码开始,直到错误行(第20行)如下所示:

#!/usr/bin/env python

import os
import sys
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
import time

if __name__ == "__main__":
    options = Options()
    options.add_argument('-headless')
    options.add_argument('log_path = "/usr/local/bin/geckodriver.log"')
    # ~/Library/PythonDenis/geckodriver.log
    # /usr/local/bin/geckodriver.log
    driver = Firefox(executable_path = '/usr/local/bin/geckodriver', options = options)
    wait = WebDriverWait(driver, timeout = 10)

版本:

  • Python 3.7.0
  • 硒3.14.1
  • geckodriver 0.23.0
  • FireFox 62.0.3
  • Mac OS Mojave 10.14.1

通过geckodriver.log寻找任何帮助解决我的问题的方法。因为我尝试了多种方法来更改代码,更改路径,文件位置等。

0 个答案:

没有答案