Tôi đã tìm thấy câu trả lời, bên dưới. Trong ngắn hạn, sai thụt lề trong ItemPipeline khiến nó trở về None.Spider phế phẩm trả về Không thay vì mục
Tôi đã cố gắng viết CrawlSpider trong Scrapy, chưa từng làm việc với python trước đây. Spider thu thập dữ liệu, gọi hàm gọi lại, trích xuất dữ liệu và điền vào mục, nhưng nó luôn trả về Không. Tôi đã thử nghiệm nó với một cuộc gọi in bài báo, mọi thứ đều theo thứ tự. Tôi đã thử điều này cả với năng suất và lợi nhuận (mặc dù tôi vẫn không hiểu sự khác biệt). Thành thật mà nói, tôi ra khỏi ý tưởng. Xuống dưới là function.//edit callback thêm mã nhện cũng
class ZeitSpider(CrawlSpider):
name= xxxx
allowed_domains = ['example.com']
start_urls = ['http://www.example.com/%d/%d' %(JAHR,39)]
rules = (Rule(SgmlLinkExtractor(restrict_xpaths=('//ul[@class="teaserlist"]/li[@class="archiveteaser"]/h4[@class="title"]')),callback='parse_url',follow=True),)
def parse_url(self,response):
def parse_url(self,response):
hxs = HtmlXPathSelector(response)
article = Article()
article['url']= response.url.encode('UTF-8',errors='strict')
article['author']= hxs.select('//div[@id="informatives"]/ul[@class="tools"]/li[@class="author first"]/text()').extract().pop().encode('UTF-8',errors='strict')
article['title']= hxs.select('//div[@class="articleheader"]/h1/span[@class="title"]/text()').extract().pop().encode('UTF-8',errors='strict')
article['text']= hxs.select('//div[@id="main"]/p/text()').extract().pop().encode('UTF-8',errors='strict')
article['excerpt'] = hxs.select('//p[@class="excerpt"]/text()').extract().pop().encode('UTF-8',errors='strict')
yield article
và định nghĩa mục
class Article(Item):
url=Field()
author=Field()
text=Field()
title=Field()
excerpt=Field()
CẢM ƠN BẠN. Thông báo lỗi là đối tượng ''NoneType' không có thuộc tính 'iterkeys''. Có thể nó có thể giúp Google chuyển hướng đến đây. – KrisWebDev