如何禁用或更改ghostdriver.log的路径? [英] How to disable or change the path of ghostdriver.log?

查看:270
本文介绍了如何禁用或更改ghostdriver.log的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是直截了当的,但某些情况下可能会有所帮助.

我正在尝试使用selenium和phantomjs作为下载器时部署scrapy.但是问题在于,它一直说要在部署时拒绝权限.因此,我想更改ghostdriver.log的路径或仅将其禁用.看着phantomjs -h和ghostdriver github页面,我找不到答案,我的朋友google也让我失望了.

$ scrapy deploy
Building egg of crawler-1370960743
'build/scripts-2.7' does not exist -- can't clean it
zip_safe flag not set; analyzing archive contents...
tests.fake_responses.__init__: module references __file__
Deploying crawler-1370960743 to http://localhost:6800/addversion.json
Server response (200):
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/scrapyd/webservice.py", line 18, in render
    return JsonResource.render(self, txrequest)
  File "/usr/lib/pymodules/python2.7/scrapy/utils/txweb.py", line 10, in render
    r = resource.Resource.render(self, txrequest)
  File "/usr/lib/python2.7/dist-packages/twisted/web/resource.py", line 216, in render
    return m(request)
  File "/usr/lib/pymodules/python2.7/scrapyd/webservice.py", line 66, in render_POST
    spiders = get_spider_list(project)
  File "/usr/lib/pymodules/python2.7/scrapyd/utils.py", line 65, in get_spider_list
    raise RuntimeError(msg.splitlines()[-1])
RuntimeError: IOError: [Errno 13] Permission denied: 'ghostdriver.log

解决方案

在使用PhantomJS驱动程序时,请添加以下参数:

driver = webdriver.PhantomJS(service_log_path='/var/log/phantomjs/ghostdriver.log')

相关的代码,虽然可以选择关闭日志记录,但似乎还不支持:

selenium/webdriver/phantomjs/service.py

class Service(object):
    """
    Object that manages the starting and stopping of PhantomJS / Ghostdriver
    """

    def __init__(self, executable_path, port=0, service_args=None, log_path=None):
        """
        Creates a new instance of the Service

        :Args:
         - executable_path : Path to PhantomJS binary
         - port : Port the service is running on
         - service_args : A List of other command line options to pass to PhantomJS
         - log_path: Path for PhantomJS service to log to
        """

        self.port = port
        self.path = executable_path
        self.service_args= service_args
        if self.port == 0:
            self.port = utils.free_port()
        if self.service_args is None:
            self.service_args = []
        self.service_args.insert(0, self.path)
        self.service_args.append("--webdriver=%d" % self.port)
        if not log_path:
            log_path = "ghostdriver.log"
        self._log = open(log_path, 'w')

Question is straightfoward, but some context may help.

I'm trying to deploy scrapy while using selenium and phantomjs as downloader. But the problem is that it keeps on saying permission denied when trying to deploy. So I want to change the path of ghostdriver.log or just disable it. Looking at phantomjs -h and ghostdriver github page I couldn't find the answer, my friend google let me down also.

$ scrapy deploy
Building egg of crawler-1370960743
'build/scripts-2.7' does not exist -- can't clean it
zip_safe flag not set; analyzing archive contents...
tests.fake_responses.__init__: module references __file__
Deploying crawler-1370960743 to http://localhost:6800/addversion.json
Server response (200):
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/scrapyd/webservice.py", line 18, in render
    return JsonResource.render(self, txrequest)
  File "/usr/lib/pymodules/python2.7/scrapy/utils/txweb.py", line 10, in render
    r = resource.Resource.render(self, txrequest)
  File "/usr/lib/python2.7/dist-packages/twisted/web/resource.py", line 216, in render
    return m(request)
  File "/usr/lib/pymodules/python2.7/scrapyd/webservice.py", line 66, in render_POST
    spiders = get_spider_list(project)
  File "/usr/lib/pymodules/python2.7/scrapyd/utils.py", line 65, in get_spider_list
    raise RuntimeError(msg.splitlines()[-1])
RuntimeError: IOError: [Errno 13] Permission denied: 'ghostdriver.log

解决方案

When using the PhantomJS driver add the following parameter:

driver = webdriver.PhantomJS(service_log_path='/var/log/phantomjs/ghostdriver.log')

Related code, would be nice to have an option to turn off logging though, seems thats not supported:

selenium/webdriver/phantomjs/service.py

class Service(object):
    """
    Object that manages the starting and stopping of PhantomJS / Ghostdriver
    """

    def __init__(self, executable_path, port=0, service_args=None, log_path=None):
        """
        Creates a new instance of the Service

        :Args:
         - executable_path : Path to PhantomJS binary
         - port : Port the service is running on
         - service_args : A List of other command line options to pass to PhantomJS
         - log_path: Path for PhantomJS service to log to
        """

        self.port = port
        self.path = executable_path
        self.service_args= service_args
        if self.port == 0:
            self.port = utils.free_port()
        if self.service_args is None:
            self.service_args = []
        self.service_args.insert(0, self.path)
        self.service_args.append("--webdriver=%d" % self.port)
        if not log_path:
            log_path = "ghostdriver.log"
        self._log = open(log_path, 'w')

这篇关于如何禁用或更改ghostdriver.log的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆