python京东商品订单提交

import requests
import time

requests.packages.urllib3.disable_warnings()
session = requests.session()

session.headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/531.36",
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
    "Connection": "keep-alive"
}
#cookie字典
manual_cookies = {}
#我的订单链接
targetURL = 'https://order.jd.com/center/list.action'
####cookie在用电脑登录京东后,我的订单页,鼠标右键选检查,Network项,按F5刷####新,找到list.action的Headers下面的Cookie:,然后把后面的一长串复制过来####就可以了
cookies_String = "这里改成自己的cookie"
for item in cookies_String.split(';'):
    name, value = item.strip().split('=', 1)
    # 用=号分割,分割1次
    manual_cookies[name] = value
    # 为字典cookies添加内容
#提取cookie
cookiesJar = requests.utils.cookiejar_from_dict(manual_cookies, cookiejar=None, overwrite=True)
session.cookies = cookiesJar

response = session.get(url=targetURL)
#print(response.text)
#商品链接,那一串数字改成自己想下单的东西,3571305是商品id
goodurl = 'https://item.jd.com/3571305.html'
response1 = session.get(goodurl)
#print(response1.text)
#加入购物车链接
addToCartUrl = "https://cart.jd.com/gate.action?pid=3571305&pcount=1&ptype=1"
response2 = session.get(url=addToCartUrl)
#购物车详情链接
checkoutUrl = "https://cart.jd.com/cart.action"
payload = {
        'rid': str(int(time.time() * 1000)),
    }
response3 = session.get(url=checkoutUrl, params=payload)

orderInfoUrl = "https://trade.jd.com/shopping/order/getOrderInfo.action"
response4 = session.get(url=orderInfoUrl)
#提交订单链接
url = 'https://trade.jd.com/shopping/order/submitOrder.action'
data = {
        'overseaPurchaseCookies': '',
        'vendorRemarks': '[]',
        'submitOrderParam.sopNotPutInvoice': 'false',
        'submitOrderParam.trackID': 'TestTrackId',
        'submitOrderParam.ignorePriceChange': '0',
        'submitOrderParam.btSupport': '0',
        'riskControl': '',
        'submitOrderParam.isBestCoupon': 1,
        'submitOrderParam.jxj': 1,
        'submitOrderParam.trackId': '637c09fcf9ae0bd3fa0d17d7009f5f64',  # Todo: need to get trackId
        # 'submitOrderParam.eid': eid,
        # 'submitOrderParam.fp': fp,
        'submitOrderParam.needCheck': 1,
}

headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/531.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
        "Referer": "http://trade.jd.com/shopping/order/getOrderInfo.action",
        "Connection": "keep-alive",
        'Host': 'trade.jd.com',
    }
response5 = session.post(url=url,data=data,headers=headers)

你可能感兴趣的:(python京东商品订单提交)