Running scrapy from script (beginner)

元气小坏坏 提交于 2019-12-06 08:25:57

Basically you have three options;

  • install the 'spiders' directory as a module in your PYTHONPATH
  • Put the 'ebay.py' file in the same directory as your script, and just import ebay.
  • modify your python path so python can find your spider.

For the third option, you have to create a file __init__.py in the spiders directory. It can be empty. Then you have to modify your script as follows (assuming that spiders is a subdirectory of the directory your program is running from):

import os
import sys
sys.path.append(os.getcwd()+'/spiders')
print sys.path
from spiders import ebay

You can try relative import feature of python to import modules from the directory relative to your python script. The reason you are not able to import the module because spiders module is not your PYTHON_PATH.

from .spiders import ebay

Note: The dot before spiders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!