问题描述
我是 Python 新手,目前正在学习使用蜘蛛抓取网页。按照教程,我坚持使用 Python 进行相对导入。
这是我当前文件夹的结构(由scrapy startproject p1
提供):
我的items.py文件:
# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html
import scrapy
class Test(scrapy.Item):
# define the fields for your item here like:
# name = scrapy.Field()
title = scrapy.Field()
price = scrapy.Field()
pass
在我的 filetwo.py 中,它包含:
import scrapy
from p1.items import Test
当我运行代码时,我得到“ModuleNotFoundError: No module named 'p1'”
我也在网上看到一些人面临同样的问题,所以我尝试了 ..items import Test
,但仍然没有奏效。它给了我错误:ImportError: attempted relative import with no kNown parent package
有人能给我一盏灯吗?
提前致谢!