gpt4 book ai didi

scrapy - 如何禁用或更改 ghostdriver.log 的路径?

转载 作者:行者123 更新时间:2023-12-03 10:22:56 24 4
gpt4 key购买 nike

问题很简单,但一些上下文可能会有所帮助。

我正在尝试在使用 selenium 和 phantomjs 作为下载器时部署scrapy。但问题是它在尝试部署时一直说权限被拒绝。所以我想改变ghostdriver.log的路径或者只是禁用它。查看 phantomjs -h 和 ghostdriver github 页面我找不到答案,我的 friend 谷歌也让我失望。

$ 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 /网络驱动程序/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')

关于scrapy - 如何禁用或更改 ghostdriver.log 的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17048594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com