2014-09-27 103 views
0

Im新增Python/Scrapy。使用python2.7Python/Scrapy導入錯誤:無法導入名稱

我的錯誤:

line 5 in module from scrapy.item import wikispiderItem 
Import Error: Can not import name wikispiderItem 

文件夾/文件結構

C:\wikispider\wikispider 

    -_init_.py 
    -items.py 
    -pipelines.py 
    -settings.py 
      -_init_.py 
      -wikiSpider.py 

從scrapy.items進口商品items.py代碼

,現場,鏈接

class wikispiderItem(scrapy.items): 
    # define the fields for your item here like: 
    # name = scrapy.Field() 
    hxs = Field() 
    heading = Field() 
    link = Field() 

wikispider.py代碼

from scrapy.contrib.spiders import CrawlSpider, Rule 
from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor 
from scrapy.selector import HtmlXPathSelector 
from scrapy.http import Request 
from scrapy.item import wikispiderItem 

class wikiSpider(CrawlSpider): 
    name = "wikiSpider" 
    allowed_domains = ['wikipedia.org'] 
    start_urls = ['http://en.wikipedia.org/wiki/Mathematics'] 

    rules = (
     Rule(SgmlLinkExtractor(restrict_xpaths=('//div[@class="mw-body"]//a/@href'))), 
     Rule(SgmlLinkExtractor(allow=("http://en.wikipedia.org/wiki/",)),callback='parse_item'), 
     ) 
    def parse_item(self, response): 
     hxs =HtmlXPathSelector(response) 
     print hxs.select('//h1[@class="firstHeading"]/span/text()').extract() 
     headng = hxs.select('//h1[@class="firstHeading"]/span/text()').extract() 

回答

1

from wikispider.items import wikispiderItem

items.py應該是:

import scrapy 


class wikispiderItem(scrapy.Item): 
    # define the fields for your item here like: 
    # name = scrapy.Field() 
    hxs = scrapy.Field() 
    heading = scrapy.Field() 
    link = scrapy.Field() 
-1
from scrapy.item import wikispiderItem 

wikispider.py上面一行應該是...

from wikispider.items import wikispiderItem 
相關問題