url_rl = "https://www.yijiupi.com/v31/Product/ListProduct" payload = ‘{"currentPage":1,"data":{"sonCategoryId":"%s","categoryIds":["%s"],"saleModel":-1,"sort":0,"currentPage":1,"pageSize":60},"pageSize":60,"addressId":1745761,"deviceType":3}‘%(cat_id,cat_id) # return [scrapy.Request(url=url_rl, body=json.dumps(payload), method="POST", callback=self.get_page_num)] #这里的payload之前是字典类型,所以要换成字符串类型json.dumps(payload),但是之后的payload就是字符串类型了,所以直接写payload就行 request = scrapy.Request(url=url_rl, body=payload, method="POST", callback=self.get_page_sum) #return [scrapy.Request(url=url_rl, body=json.dumps(payload), method="POST", callback=self.get_page_num)]
yield request
这里的payload之前是字典类型,用return发送请求是需要字符串类型,所以要换成字符串类型json.dumps(payload),在用yield发送请求是需要的是字典类型,所以直接写payload就行,上面的是yield发送请求,所以body直接等于payload就可以了。
原文地址:https://www.cnblogs.com/qiaoer1993/p/10802735.html
时间: 2024-10-08 15:42:35