我在终端 scrapy shell 中运行此代码,它会产生一个错误作为 ValueError Traceback。 要解压缩的值太多(预期为 2)。例如:品牌 - A ,猫 - AA,BB,CC,DD 品牌 - B , 猫 - AA,SS,DD,FF
scrapy shell
cats = response.xpath('//*[@class="leftNavCategoriesNodePopup"]')
brands = response.xpath('//*[@class="leftNavCategoriesNode"]')
for cat, brand in cats, brands:
ca = cat.xpath('.//*[@class="leftNavCategoriesNodePopupColumn"]/a/@href').extract()
br = brand.xpath('.//*[@class="leftNavCategoriesNodeName"]/text()').extract()
print(ca)
print(br)
值错误回溯(最近一次调用)
你确定,猫+品牌的长度相同吗? 如果是,则用作:
for cat, brand in zip(cats, brands):
#Your work goes here.
cats = response.xpath('//*[@class="leftNavCategoriesNodePopup"]')
brands = response.xpath('//*[@class="leftNavCategoriesNode"]')
for cat,brand in zip(cats, brands):
ca = cat.xpath('.//*[@class="leftNavCategoriesNodePopupColumn"]/a')
br = brand.xpath('.//*[@class="leftNavCategoriesNodeName"]/text()').extract()
for c in ca:
cq = c.xpath('.//@href').extract()
yield{'br':br, 'cq':cq}