G
G
gadzhi152016-07-17 14:11:45
Python
gadzhi15, 2016-07-17 14:11:45

Error when launching a spider in Scrapy. How to win?

There is a spider

# -*- coding: utf-8 -*-



from quoka.items import QuokaItem
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
from scrapy.loader.processors import TakeFirst
from scrapy.loader import XPathItemLoader
from scrapy.selector import HtmlXPathSelector

class QuokaLoader(XPathItemLoader):
    default_output_processor = TakeFirst()


class QuokaSpider(CrawlSpider):

    name = "quoka"
    allowed_domains = ["quoka.de"]
    start_urls = ["http://www.quoka.de/immobilien/bueros-gewerbeflaechen/"]

    rules = (
             Rule(LinkExtractor(allow=('kleinanzeigen/cat_27_2710_ct_0_page_')), follow=True),
             Rule(LinkExtractor(allow=('immobilien/bueros-gewerbeflaechen/')), callback='parse_item'),
             )

    def parse_item(self, response):
        hxs = HtmlXPathSelector(response)
        l = QuokaLoader(QuokaItem(), hxs)

        #
        l.add_xpath('date',response.xpath("/html/body/div[3]/div[2]/div[1]/main/div[8]/div/div[2]/strong/span/text()").extract())
        l.add_xpath('cost',response.xpath("/html/body/div[3]/div[2]/div[1]/main/div[8]/div/div[3]/div[2]/div[2]/text()").extract())
       # l.add_value('url', response.url)

        return l.load_item()

I run it with sudo scrapy crawl quoka_spider.py .
After that, the following errors are displayed:
/home/gadzhibala/PycharmProjects/quoka/quoka/spiders/quoka_spider.py:14: ScrapyDeprecationWarning: quoka.spiders.quoka_spider.QuokaLoader inherits from deprecated class scrapy.loader.XPathItemLoader, please inherit from scrapy.loader.ItemLoader. (warning only on first subclass, there may be others)
  class QuokaLoader(XPathItemLoader):
2016-07-17 14:07:01 [scrapy] INFO: Scrapy 1.1.1 started (bot: quoka)
2016-07-17 14:07:01 [scrapy] INFO: Overridden settings: {'BOT_NAME': 'quoka', 'SPIDER_MODULES': ['quoka.spiders'], 'ROBOTSTXT_OBEY': True, 'NEWSPIDER_MODULE': 'quoka.spiders'}
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/scrapy/spiderloader.py", line 41, in load
    return self._spiders[spider_name]
KeyError: 'quoka_spider.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/scrapy", line 11, in <module>
    sys.exit(execute())
  File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 142, in execute
    _run_print_help(parser, _run_command, cmd, args, opts)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 88, in _run_print_help
    func(*a, **kw)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/cmdline.py", line 149, in _run_command
    cmd.run(args, opts)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/commands/crawl.py", line 57, in run
    self.crawler_process.crawl(spname, **opts.spargs)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/crawler.py", line 162, in crawl
    crawler = self.create_crawler(crawler_or_spidercls)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/crawler.py", line 190, in create_crawler
    return self._create_crawler(crawler_or_spidercls)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/crawler.py", line 194, in _create_crawler
    spidercls = self.spider_loader.load(spidercls)
  File "/usr/local/lib/python3.5/dist-packages/scrapy/spiderloader.py", line 43, in load
    raise KeyError("Spider not found: {}".format(spider_name))
KeyError: 'Spider not found: quoka_spider.py'

Tried uninstalling and reinstalling Scrapy but same result

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2016-07-17
@gadzhi15

name = "quoka"
try running scrapy crawl quoka

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question