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()