[英]Scrapy ImportError: cannot import name “______Item”
I am new to python 2.7 & Scrapy, and receive the following error when running "scrapy crawl prop$" from the command line. 我是python 2.7和Scrapy的新手,从命令行运行“ scrapy crawl prop $”时收到以下错误。 I assume this is a simple fix, thus, any assistance is greatly appreciated!
我认为这是一个简单的解决方法,因此,非常感谢您的协助!
Error Message: 错误信息:
File"C:\Anaconda2\propub\propub\spiders\propub_spider.py", line 4, in <module>
from propub.items import propubItem
ImportError: cannot import name propubItem
items.py
: items.py
:
import scrapy
from scrapy.item import Item, Field
class PropubItem(scrapy.Item):
payee = scrapy.Field()
link = scrapy.Field()
city = scrapy.Field()
state = scrapy.Field()
company = scrapy.Field()
amount = scrapy.Field()
pass
propub_spiders.py
: propub_spiders.py
:
import scrapy
from scrapy.contrib.spiders import CrawlSpider, Rule
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor
from propub.items import propubItem
class propubSpider(CrawlSpider):
name = 'prop$'
allowed_domains = ['https://projects.org']
start_urls = [
'https://projects/search?state%5Bid%5D=33',
'https://projects/search?page=2&state%5Bid%5D=33',
'https://projects/search?page=3&state%5Bid%5D=33']
rules = (Rule(SgmlLinkExtractor(allow=('\\search?page=\\d')), 'parse_start_url', follow=True),)
def parse(self, response):
for sel in response.xpath('//*[@id="payments_list"]/tbody'):
item = propubItem()
item['payee'] = sel.xpath('tr[1]/td[1]/a[2]/text()').extract()
item['link'] = sel.xpath('tr[1]/td[1]/a[1]/@href').extract()
item['city'] = sel.xpath('tr[1]/td[2]/text()').extract()
item['state'] = sel.xpath('tr[1]/td[3]/text()').extract()
item['company'] = sel.xpath('tr[1]/td[4]').extract()
item['amount'] = sel.xpath('tr[1]/td[7]/span/text()').extract()
yield item
It is just a typo. 这只是一个错字。 Your item class name starts with an upper case letter .
您的商品类名称以大写字母开头 。
Replace: 更换:
from propub.items import propubItem
with: 有:
from propub.items import PropubItem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.