如何开始使用 Scrapy Web 服务?
How to get started with Scrapy Web Service?
我已经使用 Scrapy 很长时间了,我必须说我爱上了它。最近,我了解了Scrapy Web Service。但我无法弄清楚它是如何工作的。或者我如何使用它来监控我当前的蜘蛛。
正在寻找文档或入门指南。
所以,that document you've linked is the closest thing to a guide there is. It doesn't do much hand-holding but should be enough to get you going -- it even comes with an example client script。
简而言之,the web service is enabled by default, and it answers to HTTP requests using the JSON RPC 远程调用协议。
您可以在 Scrapy 项目中启动 scrapy shell
后尝试,将浏览器指向:http://localhost:6080。您应该会看到一个显示可用资源的页面:
{"resources": ["enginestatus", "stats", "crawler"]}
从现在开始,您将进一步了解 JSON RPC Version 2,以构建正确的调用——这里是一个使用 requests
:
的示例
>>> import requests, json
>>> jsonrpc_call = {'jsonrpc': '2.0', 'method': 'list', 'params': [], 'id': 1}
>>> resource = 'http://localhost:6080/crawler/spiders'
>>> requests.post(resource, data=json.dumps(jsonrpc_call)).json()
{u'id': 1, u'jsonrpc': u'2.0', u'result': [u'spider1', u'spider2']}
重要提示: 你应该知道这个 JSON RPC 服务已经从 Scrapy 中提取出来用于下一个版本,现在作为一个单独的项目存在:https://github.com/scrapy/scrapy-jsonrpc。所以,升级到 Scrapy 1.0 时要做好准备。 ;)
我已经使用 Scrapy 很长时间了,我必须说我爱上了它。最近,我了解了Scrapy Web Service。但我无法弄清楚它是如何工作的。或者我如何使用它来监控我当前的蜘蛛。
正在寻找文档或入门指南。
所以,that document you've linked is the closest thing to a guide there is. It doesn't do much hand-holding but should be enough to get you going -- it even comes with an example client script。
简而言之,the web service is enabled by default, and it answers to HTTP requests using the JSON RPC 远程调用协议。
您可以在 Scrapy 项目中启动 scrapy shell
后尝试,将浏览器指向:http://localhost:6080。您应该会看到一个显示可用资源的页面:
{"resources": ["enginestatus", "stats", "crawler"]}
从现在开始,您将进一步了解 JSON RPC Version 2,以构建正确的调用——这里是一个使用 requests
:
>>> import requests, json
>>> jsonrpc_call = {'jsonrpc': '2.0', 'method': 'list', 'params': [], 'id': 1}
>>> resource = 'http://localhost:6080/crawler/spiders'
>>> requests.post(resource, data=json.dumps(jsonrpc_call)).json()
{u'id': 1, u'jsonrpc': u'2.0', u'result': [u'spider1', u'spider2']}
重要提示: 你应该知道这个 JSON RPC 服务已经从 Scrapy 中提取出来用于下一个版本,现在作为一个单独的项目存在:https://github.com/scrapy/scrapy-jsonrpc。所以,升级到 Scrapy 1.0 时要做好准备。 ;)