SidGabriel
SidGabriel

Reputation: 185

How to access items class Scrapy

I have a persistent issue on the scrapy projects I start.

Wherever I put items.py, it seems not to be recognized inside the spider. I must be missing something.

My project is named scrapybot.

To summarize, I have:

scrapybot
├──scrapybot 
   ├──__init__.py
   ├──core.py
   ├──custom_middlewares.py
   ├──middlewares.py
   ├──pipelines.py
   ├──settings.py
   ├──spiders
      ├──__init__.py
      ├──amazon_bot.py
      ├──ebay_bot.py
      ├──items.py

I want to put items.py into the spider folder and import it like this:

>>> from spiders.items import ScrapybotItem
ModuleNotFoundError: No module named 'spiders'

Or like this:

>>> from items import ScrapybotItem
ModuleNotFoundError: No module named 'items'

Do you know why I can't use imports this way? Is this the correct way?

Upvotes: 1

Views: 48

Answers (1)

Guillaume
Guillaume

Reputation: 1879

You forgot the name of the top level package: scrapybot.

Try like this:

>>> from scrapybot.spiders.items import ScrapybotItem

Upvotes: 1

Related Questions