0
votes

I cannot run my spider, using the shell command "scrapy crawl kbb," due to an error in finding my items module.

My folder path follows the standard scrapy orientation.

# -*- coding: utf-8 -*-
import scrapy
from scrapy.loader import ItemLoader
from kbb.items import KelleyItem


class KbbSpider(scrapy.Spider):
    name = 'kbb'
    allowed_domains = ['kbb.com']
    start_urls = ['https://www.kbb.com/cars-for-sale/cars/?distance=75']

    def parse(self, response):
        l = ItemLoader(item=Product(), response=response)
        l.xpath('Title','//div[@class="listings-container-redesign"]/div/div/a/text()').extract()
        l.xpath('Price','//div[@class="listings-container-redesign"]/div/div/div/div/span/text()').extract()
        return l.load_item()

items.py:

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

# Define here the models for your scraped items
#
# See documentation in:
# https://doc.scrapy.org/en/latest/topics/items.html

import scrapy


class KelleyItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    title = scrapy.Field()
    price = scrapy.Field()

When running this via the shell command, "scrapy crawl kbb," I get the following error: "ModuleNotFoundError: No module named kbb"

2

2 Answers

1
votes

If your project use the standard scrapy folder structure, you can use this:

from ..items import KelleyItem

See relative imports in Python

0
votes
from items import KelleyItem

Try this one.