Python+京東預約搶,讓你秒搶心儀商品,無需手動刷新等待,快來看看如何利用Python自動預約京東商品吧!
# 導入所需模塊 import requests, json, re, time # 設置請求頭 header = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36 Edg/88.0.705.50", "Content-Type": "application/x-www-form-urlencoded" } # 設置商品鏈接 url = "https://yushou.jd.com/service/confirm?callback=jsonpCallback&p=60443843549&ptype=1&skuId=10028442300625" # 發送請求 response = requests.get(url, headers=header) # 解析返回數據 price_reg = re.compile(r"\"price\":\"(\d*\.\d*)\",\"") price = float(price_reg.findall(response.text)[0]) yuyueId_reg = re.compile(r"\"yuyueId\":\"(\d*)\"}") yuyueId = yuyueId_reg.findall(response.text)[0] # 預約參數 data = { "sku": "10028442300625", "num": "1", "price": str(price), "yuyueId": yuyueId, "vid": "" } # 設置預約鏈接 reserve_url = "https://yushou.jd.com/youshujson/createOrder" # 發送預約請求 reserve_response = requests.post(reserve_url, data=data, headers=header) # 解析返回數據 content = json.loads(reserve_response.text) if content['success']: print("預約成功!") else: print("預約失敗")
以上代碼可以自動獲取商品價格和預約ID,并以此為參數向京東服務器發送預約請求,實現自動搶購的效果。
上一篇gson解析json屬性
下一篇python 年日時間戳