Home > front end >  Unshapable list error when scraping information
Unshapable list error when scraping information

Time:06-30

I am trying to extract information but they will give me error of unshapable list these is page link enter image description here

But I want output like these: enter image description here

CodePudding user response:

Dictionary keys cannot be mutable and must be hashable. Try this:

def parse(self, response):
    wev={}
    tic = response.xpath("//div[@class='line_list_K']//div//span//text()").getall()
    det = response.xpath("//div[@class='line_list_K']//div//div//text()").getall()
    wev[tuple(tic)]=[i.strip() for i in det]
    print(wev)
    yield wev

or even simpler:

def parse(self, response):
    tic = response.xpath("//div[@class='line_list_K']//div//span//text()").getall()
    det = response.xpath("//div[@class='line_list_K']//div//div//text()").getall()
    yield {tuple(tic): [i.strip() for i in det]}

CodePudding user response:

Check the datatype of tic. It is most probably a list that cannot be dictionary keys. Maybe you can cast it to a tuple based on your requirements.

  • Related