Can't get Scrapy pipeline to work
Asked Answered
R

2

8

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?

Rayerayfield answered 3/11, 2010 at 19:21 Comment(0)
R
8

Got it! The line needs to go in the settings module for the project. Now it works!

Rayerayfield answered 4/11, 2010 at 20:17 Comment(2)
No, my client may have put it up somewhere, but not my place to open source it I'm afraid.Rayerayfield
i had to use ITEM_PIPELINES as a dict instead of a list in the settings fileFaust
I
0

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!)

Interpol answered 3/11, 2010 at 19:27 Comment(3)
Thanks for spotting that (can't believe I missed it!), but it still doesn't work unfortunatelyRayerayfield
It's still my bet at what's wrong, keep checking! :P (if not, I'm out of ideas...)Interpol
I'll have another look. Cheers!Rayerayfield

© 2022 - 2024 — McMap. All rights reserved.