无法让 Scrapy 管道工作
我有使用 Scrapy 框架编写的蜘蛛。我在让任何管道正常工作时遇到一些麻烦。我的 pipelines.py 中有以下代码:
class FilePipeline(object):
def __init__(self):
self.file = open('items.txt', 'wb')
def process_item(self, item, spider):
line = item['title'] + '\n'
self.file.write(line)
return item
并且我的 CrawlSpider 子类具有此行来激活此类的管道。
ITEM_PIPELINES = [
'event.pipelines.FilePipeline'
]
然而,当我使用它运行它时,
scrapy crawl my_spider
我得到一条
2010-11-03 20:24:06+0000 [scrapy] DEBUG: Enabled item pipelines:
没有管道的行(我认为这是日志记录应该输出它们的地方)。
我尝试查看文档,但似乎没有整个项目的完整示例来查看我是否错过了任何内容。
关于下一步尝试什么有什么建议吗?或者在哪里寻找更多文档?
I have spider that I have written using the Scrapy framework. I am having some trouble getting any pipelines to work. I have the following code in my pipelines.py:
class FilePipeline(object):
def __init__(self):
self.file = open('items.txt', 'wb')
def process_item(self, item, spider):
line = item['title'] + '\n'
self.file.write(line)
return item
and my CrawlSpider subclass has this line to activate the pipeline for this class.
ITEM_PIPELINES = [
'event.pipelines.FilePipeline'
]
However when I run it using
scrapy crawl my_spider
I get a line that says
2010-11-03 20:24:06+0000 [scrapy] DEBUG: Enabled item pipelines:
with no pipelines (I presume this is where the logging should output them).
I have tried looking through the documentation but there doesn't seem to be any full examples of a whole project to see if I have missed anything.
Any suggestions on what to try next? or where to look for further documentation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
知道了!该行需要进入项目的设置模块。现在可以了!
Got it! The line needs to go in the settings module for the project. Now it works!
我愿意打赌,这是管道一词的大小写差异:
Pipeline vs. PipeLine
我注意到
'event.pipelines.FilePipeline'
使用前者,而您的代码使用后者:你的文件名使用什么?(我多次成为这个拼写错误的受害者!)
I'm willing to bet that it's a capitalisation difference in the word pipeline somewhere:
Pipeline vs. PipeLine
I notice
'event.pipelines.FilePipeline'
uses the former, whereas your code uses the latter: which do your filenames use?(I have fallen victim to this spelling mistake many times!)