Skip to content

Commit 0f755ab

Browse files
committed
scrapy
1 parent 0486025 commit 0f755ab

File tree

1 file changed

+36
-0
lines changed
  • scrapy/pipeline-with-arguments

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
3+
# date: 2020.01.17
4+
# https://stackoverflow.com/questions/59789768/init-missing-1-required-positional-argument-when-added-stats/
5+
6+
import scrapy
7+
8+
class MySpider(scrapy.Spider):
9+
10+
name = 'myspider'
11+
12+
start_urls = ['http://books.toscrape.com/'] #'http://quotes.toscrape.com']
13+
14+
def parse(self, response):
15+
print('url:', response.url)
16+
17+
18+
class MyPipeline(object):
19+
20+
def __init__(self, stats):
21+
print('__init__ stats:', stats)
22+
self.stats = stats
23+
24+
@classmethod
25+
def from_crawler(cls, crawler):
26+
print('from_crawler stats:', crawler.stats)
27+
return cls(crawler.stats)
28+
29+
30+
from scrapy.crawler import CrawlerProcess
31+
32+
c = CrawlerProcess({
33+
'ITEM_PIPELINES': {'__main__.MyPipeline': 1}, # used Pipeline created in current file (needs __main___)
34+
})
35+
c.crawl(MySpider)
36+
c.start()

0 commit comments

Comments
 (0)