我正在尝试获得有效载荷值" productid"到+1。但是当我使用productid + 1时,productid变量不会改变?
当我运行脚本时,产品ID保持为" 7367"何时应该更改为" 7368"
productid=7367
headers = {
"Host": "www..co.uk",
"Connection": "keep-alive",
"Content-Length": "121",
"Cache-Control": "max-age=0",
"Origin": "http://www..co.uk",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Chrome/57.0.2987.133 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.8",
}
payload = {
"attributes":"",
"product_quantity":"1",
"submit":"",
"product_id":productid+1,
"show_image_":"0",
}
print ("ProductID:"), productid
答案 0 :(得分:0)
"product_id":productid+1,
只是递增当前值并将其分配给有效负载字典而不是返回到productid变量。所以在你拥有这个
的页面的下方 print ("ProductID:"), productid
您只是将原始值打印为您没有保存到该变量的增量。
要做到这一点,您需要在脚本底部打印有效负载product_id变量,或者递增并保存回变量,如下所示
productid += 1
payload = {
"attributes":"",
"product_quantity":"1",
"submit":"",
"product_id":productid,
"show_image_":"0",
}
print ("ProductID:"), productid