问题描述
我相信一年前有人问过类似的问题,但没有找到解决方案。基本上,我正在尝试使用 POST 请求将产品从 https://www.supremenewyork.com/shop/all 添加到购物车。我首先对 https://www.supremenewyork.com/mobile_stock.json 执行 GET 以检索项目名称和 ID,然后我使用该 ID 尝试发出 POST 请求,但它不起作用。
这是我的代码:
# this is the get request
link = 'https://www.supremenewyork.com/mobile_stock.json'
response = requests.get(url=link)
data = json.loads(response.content.decode('utf-8'))
mylist = []
global mylists
mylists = mylist
for items in data['products_and_categories']:
if items != 'new':
categories = items
for x in categories.split():
for result in data['products_and_categories']['{}'.format(x)]:
# finds the name and id
if keyword in result['name'].lower():
print('Product Found!')
global name
name = result['name']
id = result['id']
# attempts to make a POST request to add to cart
post_headers = {'User-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/80.0.3987.132 Safari/537.36','x-requested-with': 'XMLHttpRequest','content-type': 'application/x-www-form-urlencoded'}
post_data = {"utf8": "%E2%9C%93","authenticity_token": "{}","h": 1,"st": 29655,"chk": "1614789969ee693a8a188da014ffe17d","s": 86171}
url = "https://www.supremenewyork.com/shop/{}/add".format(result['id'])
add_to_cart = requests.post(url=url,headers=post_headers,data=post_data)
print(id)
print(add_to_cart.text)
print(add_to_cart.status_code)
print()
我得到的控制台错误是 "cart" = []
,但状态代码是 200 (OK)
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)