I'm building spider by scrapy. I defined item like below:
class MyItem(scrapy.Item):
# define the fields for your item here like:
title = scrapy.Field()
usage=scrapy.Field()
storage=scrapy.Field()
and the title comes from the first page, usage comes from the second page and the storage comes from the third page
No I try to fetch value from webpage like below
def parse_item(self, response):
links=response.xpath('somepath')
for link in links:
name=link.xpath('text()').get()
href= 'mydomain'+link.xpath('@href').get()
yield scrapy.Request(href,callback=self.parse_info,meta={"title":name})
def parse_info(self,response):
item=MyItem()
item["title"]=response.request.meta['title']
# usage
item['usage']=response.xpath("sompath").get().strip()
# storage
storagelink = response.xpath("somepath/@href").get()
item['usage'] = scrapy.Request(storagelink ,callback=self.parse_storage,meta={"title":name})
print(item)
return item
def parse_storage(self,response):
return response.xpath("somepath/text()").get().strip()
but I can't get the usage value, the console always output:
'usage': <GET https://webaddress>,
Why? And how can I merge there data into items? Thanks!