scrapy出现:AttributeError: 'list' object has no attribute 'xpath'

这个问题一般是我们在取出多个连接的时候加上了.extract()

如(错误):

chaps = response.xpath('//*[@class="mulu_list"]//a').extract()

   for i in range(len(chaps)):
      list = ListItem()
      list['chapName'] = chaps.xpath('text()').extract()[i]
      list['chapUrl'] = chaps.xpath('@href').extract()[i]
      yield list

正确应该去掉:

chaps = response.xpath('//*[@class="mulu_list"]//a')

你可能感兴趣的:(scrapy)