Joey Chestnut Joey Chestnut - 1 year ago 94
Python Question

Python/Scrapy Import Error: Can not import name

Im new to Python/Scrapy. using python2.7

My error:

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

Folder/File Structure

C:\wikispider\wikispider code

from scrapy.items import Item, Field, Link

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

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 = ['']
start_urls = ['']

rules = (
Rule(SgmlLinkExtractor( allow=("",)),callback='parse_item'),
def parse_item(self, response):
hxs =HtmlXPathSelector(response)
headng ='//h1[@class="firstHeading"]/span/text()').extract()

Answer Source

from wikispider.items import wikispiderItem

Your should be:

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()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download