包含查询分类商品列表 mtop.wdk.classify.queryclassifyitemsv4

查询商品详细数据 mtop.wdk.detail.openservice

 

import time
import requests
import hashlib

from requests.api import post

# js源码: c.appKey || ("waptest" === d.subDomain ? "4272" : "23228014")
# 如果是 waptest appkey则是4272 否则则是 23228014
# 联系 QQ 214783030 app全接口数据
APP_KEY="23228014"


def main():
    # 需要 时间戳 和 sign两个参数
    url = "http://acs.m.taobao.com/h5/mtop.wdk.classify.queryclassifyitemsv4/1.0/?jsv=2.5.1&appKey=23228014&t={}&sign={}&type=originaljson&dataType=json&timeout=5000"
    # 13位时间戳
    timestr = int(round(time.time() * 1000))
    # header头
    headers = {
        "content-type": "application/x-www-form-urlencoded",
        "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
        "accept": "application/json"
    }


    post_data = r"""{"needFullPageSize":"true","needProperties":"0","originCatId":"205954909","trackInfo":"{\"hotSourceType\":\"hotSell_270819\",\"moudleIndex\":\"2.2\",\"spm-pre\":\"a21dw.8199429.category.2\"}","bizType":"sx","pagination":"29-10-1-0","enableTmdSelect":"0","secCatId":"205954909","enableNisitc":"0","catId":"205954909","curItemCatId":"205954909","isNOInventory":"true","shopIds":"156775275,360861272,331458382,292982260,535423019,577743005,214016065,160039352,232747349,234340026,190417236,571201201,677950313","rn":"1c7828aee56d43d788f7dfe77fc48644","catIds":"[{\"catId\":\"205954909\",\"catTemplateId\":\"3\",\"categoryType\":\"3\",\"displayProperties\":\"0\",\"enableNisitc\":\"0\",\"enableOrder\":\"0\",\"enableTmdSelect\":\"0\",\"extend\":{}}]"}"""

    # 组装参数 得到sign
    arg = f"undefined&{timestr}&{APP_KEY}&{post_data}"
    sign = hashlib.md5(arg.encode()).hexdigest()

    # 第一次请求得到 _m_h5_tk 和 _m_h5_tk_enc 两个cookie
    resp = requests.post(url.format(timestr, sign), data={"data": post_data}, headers=headers)
    resp1=resp
    print(f"第一次请求: {resp1.text}\n")

    # 需要从cookie的_m_h5_tk中得到token
    token=''
    for name, value in resp.cookies.items():
        if name == "_m_h5_tk":
            token = value.split("_")[0]
   # 再次得到时间戳
    timestr = int(round(time.time() * 1000))
    # 此次arg的第一个参数需要 token
    arg = f"{token}&{timestr}&{APP_KEY}&{post_data}"
    sign = hashlib.md5(arg.encode()).hexdigest()

    print(f"token: {token}\nsign: {sign}\n")
    ###
    #alipay  查询商品详情  shopIds 盒马门店ID itemId 商品ID
    url = "http://h5api.m.taobao.com/h5/mtop.wdk.detail.openservice/1.0/?jsv=2.5.1&appKey=23228014&t={}&sign={}&type=originaljson&dataType=json&timeout=5000"
    post_data = r'{"extParam":"false_20200707","ifSkuPanel":"false","itemId":"650472945903","poi":"118.302649,31.260759","shopIds":"189031339","showSeries":false,"showSeriesTitle":false,"skuId":0,"source":"alipay","terminal":"HEMA_APPLETS"}'
    headers = {
        "content-type": "application/x-www-form-urlencoded",
        "user-agent": "MTOPSDK%2F3.1.1.7+%28Android%3B11%3BXiaomi%3BMi+10+Pro%29",
        "accept": "application/json"
    }

    timestr = int(round(time.time() * 1000))
    # 此次arg的第一个参数需要 token
    arg = f"{token}&{timestr}&{APP_KEY}&{post_data}"
    sign = hashlib.md5(arg.encode()).hexdigest()
    resp = requests.post(url.format(timestr, sign), data={"data": post_data}, headers=headers, cookies=requests.utils.dict_from_cookiejar(resp1.cookies))
    print(f"查询详情: {resp.text}\n")
\

if __name__ == '__main__':
    main()



Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐