如下:`
def parse(self, response): # housename = response.xpath('//*[@id="content"]/div[1]/ul/li[1]/div[1]/div[1]/a/text()').extract_first() # price = response.xpath('//*[@id="content"]/div[1]/ul/li[1]/div[1]/div[6]/div[1]/span/text()').extract_first() # item = FirstspiderItem() #创建一个Item实例 # item["housename"] = housename # item["price"] = price # return item ti_list = response.xpath('//*[@id="content"]/div[1]/ul/li') for tr in ti_list: item = FirstspiderItem() # .表示从当前位置开始 #这里从li开始 item["housename"] = tr.xpath('./div[1]/div[1]/a/text()').extract_first().strip() item["price"] = tr.xpath('./div[1]/div[6]/div[1]/span/text()').extract_first().strip() yield item`其余地方不改动,重新运行项目,得到如图所示结果