我最近刚学会了刮痧。 你怎么能让羊痒交出所有的东西?在
例如,如果我想提取book
。
主页是book title
,第二层是chapter
,第三层是article
。在
class BookSpider(scrapy.spider.Spider):
name = 'book'
allowed_domains = ['book.com']
start_urls = ['http://www.book.com']
def __init__(self):
self.items = []
def parse(self, response):
link = response.xpath('//chapter').extract()
for l in links:
yield Request(l, callback=self.parse_chapter)
print self.items
def parse_chapter(self, response):
link = response.xpath('//article').extract()
for l in links:
yield Request(l, callback=self.parse_article)
return
def parse_article(self, response):
item = BookItem()
item['article'] = response.url
self.items.append(item)
return
但结果只是一张空名单。为什么self.items
无法构建?在
您需要从任何回调中返回或生成项或项列表:
相关问题 更多 >
编程相关推荐