你的解析函数parse没有接收response,你复制我这个运行看看。
class CurlieSpider(scrapy.Spider):
name = 'curlie'
allowed_domains = ['curlie.org']
start_urls = [
'https://curlie.org/Computers/Programming/Languages/Python/Books/',
'https://curlie.org/Computers/Programming/Languages/Python/Resources/']
def parse(self, response):
content_list = response.xpath('//*[@id="site-list-content"]/div[2]/div/div[3]')
for content in content_list:
item = DomeItem()
item['title'] = content.xpath('div[1]/a/text()').extract_first()
item['link'] = content.xpath('div[1]/a/@href').extract_first()
item['text'] = content.xpath('div[2]/text()').extract_first().strip()
yield item
|