@mrkovalchuk
Junior developer

Scrapy, имя паука не найдено, что могло вызвать эту ошибку?

Доброго времени суток.

Сабж: не запускается паук. Ругается вот так.
KeyError: 'Spider not found: news_spider'

Насколько понимаю, это означает что что-то с кодом паука не так. А что, понять не могу.

Ниже представлен код паучка.

news_scrap
import locale

import scrapy

from main.models import News
from ..sup import replace_date
from ..items import NewsItem


class QuotesSpider1(scrapy.Spider):
    name = "news_scrap"

    def start_requests(self):
        urls = ['http://vladivostok3000.ru/news/'
                'http://vladivostok3000.ru/events/',
                'http://vladivostok3000.ru/city/',
                'http://vladivostok3000.ru/culture/'
                ]
        for url in urls:
            yield scrapy.Request(url=url, callback=self.parse)

    def parse(self, response):
        if response.url == 'http://vladivostok3000.ru/news/':
            titles = response.css('.news_title_page a::attr(href)').extract()
            last_news_db = News.objects.latest('date')
            for last_news in titles:
                if last_news == last_news_db.site_source:
                    self.logger.info('Base actual')
                else:
                    yield scrapy.Request(response.urljoin(last_news), callback=self.parse_news)

            page_count = 1
            next_page = response.css('.next::attr(href)').extract_first()
            if next_page is not None and page_count <= 5:
                next_page = response.urljoin(next_page)
                page_count += 1
                yield scrapy.Request(next_page, callback=self.parse)

        elif response.url == 'http://vladivostok3000.ru/events/':
            pass
        elif response.url == 'http://vladivostok3000.ru/city/':
            pass
        elif response.url == 'http://vladivostok3000.ru/culture/':
           pass
        else:
            pass

    def parse_news(self, response):
        self.logger.info('Hi, this is parse_news! %s', response.url)
        item = NewsItem()
        item['title'] = response.xpath('//div[@class="news_title"]/text()').extract()[0]
        self.logger.info('Title: success')
        item['image'] = response.xpath('//div[@class="news_pic"]/img/@src').extract()[0]
        self.logger.info('Image_link: success')
        item['content'] = ' '.join(response.xpath('//div[@class="post_content"]/p/text()').extract()).replace('\xa0',
                                                                                                              ' ')
        self.logger.info('Content: success')
        item['site_source'] = 'http://' + response.xpath('//meta[@property="og:url"]/@content').extract()[0]
        self.logger.info('Site: success')
        locale.setlocale(locale.LC_ALL, 'ru_RU.UTF-8')
        item['date'] = replace_date(response.xpath('//div[@class="post_section"]/text()').extract()[0])
        self.logger.info('Date: success')

        yield item
  • Вопрос задан
  • 848 просмотров
Решения вопроса 1
@screen_sailor
The Screen Is Not Enough
news_scrap -- то имя ? поэтому и пишет, что не нашёл news_spider
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
@Verz1Lka
Web scraping expert
name = "news_scrap"
Это ваше имя паука
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы