为什么会报错from tutorial.items import DmozItem会报错?
items.py文件
#-*- coding: utf-8 -
import scrapy
class DmozItem (scrapy.Item):
title= scrapy.Field()
link=scrapy.Field()
desc=scrapy.Fieldd()
dmo_spider.py文件
import scrapy
from tutorial.items import DmozItem
class DmozSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = ["dmoz.org"]
start_urls = [
"
http://www.dmoz.org/Computers/Programming/Languages/Python/Books/
",
"
http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/
"
]
def parse(self, response):
for sel in response.xpath('//ul/li'):
item = DmozItem()
item['title']= sel.xpath('a/text()').extract()
item['ink'] = sel.xpath('a/@href').extract()
item['desc']= sel.xpath('text()').extract()
yield item
为什么在dmzo_spider.py文件加入
from tutorial.items import DmozItem
执行scrapy crawl dmoz -o items.json时会报错,
如果去掉的话就会有 item = DmozItem()
exceptions.NameError: global name 'DmozItem' is not defined
的报错