I am trying to use scrapyd with scrapy.
When I use this the code below it works fine.
JavaScript
x
19
19
1
import scrapy
2
from scrapy.selector import Selector
3
from scrapy.spiders import CrawlSpider
4
from shikari.items import shikariItem
5
from scrapy.http import Request
6
7
8
class Radiate(scrapy.Spider) :
9
name = "run"
10
11
allowed_domains = ["google.com"]
12
start_urls = ['http://google.com']
13
14
def parse(self, response) :
15
item = shikariItem ()
16
sel = Selector (response)
17
item['url'] = response.url
18
return item
19
But when I use it with selenium, it doesn’t
JavaScript
1
26
26
1
import scrapy
2
from pyvirtualdisplay import Display
3
from selenium import webdriver
4
from shikari.items import shikariItem
5
6
7
class Radiate(scrapy.Spider) :
8
name = "run"
9
10
allowed_domains = ["google.com"]
11
start_urls = ['http://google.com']
12
13
def __init__(self):
14
display = Display(visible=0, size=(800, 600))
15
display.start()
16
self.driver = webdriver.Chrome('/usr/bin/chromedriver')
17
18
def parse(self, response) :
19
item = shikariItem ()
20
item['url'] = self.driver.get(response.url)
21
return item
22
23
def teardown(self):
24
display.stop()
25
self.driver.close()
26
My spider never runs. In jobs it gets listed under finished, and on error log I see exceptions.TypeError: __init__() got an unexpected keyword argument '_job'
.
Here is the full error log
JavaScript
1
26
26
1
2016-02-23 19:42:06 [scrapy] INFO: Scrapy 1.0.5 started (bot: scrapybot)
2
2016-02-23 19:42:06 [scrapy] INFO: Optional features available: ssl, http11
3
2016-02-23 19:42:06 [scrapy] INFO: Overridden settings: {'NEWSPIDER_MODULE': 'shikari.spiders', 'FEED_URI': 'file:///var/www/html/shikari/scrapyd-client-master/items/shikari/run/82776010da6511e5b08d1288e0cebe8d.jl', 'CONCURRENT_REQUESTS_PER_DOMAIN': 1, 'SPIDER_MODULES': ['shikari.spiders'], 'USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:44.0) Gecko/20100101 Firefox/44.0', 'FEED_FORMAT': 'csv', 'LOG_FILE': 'logs/shikari/run/82776010da6511e5b08d1288e0cebe8d.log', 'DOWNLOAD_DELAY': 4}
4
2016-02-23 19:42:06 [scrapy] INFO: Enabled extensions: CloseSpider, FeedExporter, TelnetConsole, LogStats, CoreStats, SpiderState
5
2016-02-23 19:42:06 [twisted] ERROR: Unhandled error in Deferred:
6
2016-02-23 19:42:06 [twisted] ERROR: Unhandled Error
7
Traceback (most recent call last):
8
File "/usr/local/lib/python2.7/dist-packages/scrapy/cmdline.py", line 150, in _run_command
9
cmd.run(args, opts)
10
File "/usr/local/lib/python2.7/dist-packages/scrapy/commands/crawl.py", line 57, in run
11
self.crawler_process.crawl(spname, **opts.spargs)
12
File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 153, in crawl
13
d = crawler.crawl(*args, **kwargs)
14
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1237, in unwindGenerator
15
return _inlineCallbacks(None, gen, Deferred())
16
--- <exception caught here> ---
17
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1099, in _inlineCallbacks
18
result = g.send(result)
19
File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 70, in crawl
20
self.spider = self._create_spider(*args, **kwargs)
21
File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 80, in _create_spider
22
return self.spidercls.from_crawler(self, *args, **kwargs)
23
File "/usr/local/lib/python2.7/dist-packages/scrapy/spiders/__init__.py", line 50, in from_crawler
24
spider = cls(*args, **kwargs)
25
exceptions.TypeError: __init__() got an unexpected keyword argument '_job'
26
What do I need to do so I don’t get the error?
Advertisement
Answer
You redefined __init__
in your subclass and changed it’s signature from scrapy.Spider
. You also didn’t call scrapy.Spider
‘s __init__
method.
scrapy.Spider
source for init