heyyyitsatn 2025-08-29 20:38 采纳率: 0%
浏览 10

Shopee自动化请求购买

#shopee #request #python
Hi i'm looking for someone to help me write checkout flow for on https://shopee./api/v4/checkout/get

I already passed captcha phased, only needed to finish the flow for atc

my email anthonyle138@gmail.com

  • 写回答

4条回答 默认 最新

  • 檀越@新空间 2025-08-29 20:39
    关注

    晚上好🌙🌙🌙
    本答案参考通义千问

    你好!你提到的目标是在 Shopee 上实现自动化购买流程,并且已经通过了 Captcha 验证,现在需要完成以下步骤:

    1. 将商品加入购物车(Add to Cart)
    2. 进入结账页面(Checkout)
    3. 填写收货信息(如邮箱:anthonyle138@gmail.com
    4. 提交订单

    由于 Shopee 的 API 接口通常受到反爬虫机制、身份验证和会话管理的限制,直接使用 https://shopee./api/v4/checkout/get 这样的接口可能会遇到以下问题:

    • 缺少必要的 Cookie 或 Token
    • 未登录状态
    • 请求头不完整或不符合要求

    ✅ 重点说明

    请务必注意:

    • Shopee 不允许未经授权的自动化操作,这可能违反其服务条款。
    • 自动化购买行为可能导致你的账号被封禁。
    • 本回答仅用于学习目的,请遵守法律法规与平台规则。

    🛠️ 解决方案步骤

    1. 获取有效的 Session 和 Token

    你需要在浏览器中登录 Shopee 并获取以下信息:

    • Cookie(包含 skey, sid, user_token 等)
    • XSRF-TOKEN
    • User-Agent

    💡 可以使用浏览器开发者工具(F12)查看 Network 请求中的 Headers。

    2. 模拟 Add to Cart 操作

    import requests
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        'Cookie': 'your_cookie_here',
        'X-XSRF-TOKEN': 'your_xsrf_token_here'
    }
    
    data = {
        'item_id': '123456',  # 替换为实际商品 ID
        'variation_id': '0',
        'quantity': '1'
    }
    
    response = requests.post('https://shopee.com/api/v4/cart/add', headers=headers, json=data)
    print(response.text)
    

    🔹 如果返回 {"error": 0} 表示成功添加到购物车。


    3. 进入结账页面(Get Checkout Info)

    response = requests.get('https://shopee.com/api/v4/checkout/get', headers=headers)
    print(response.text)
    

    🔹 此接口通常会返回当前购物车的商品信息,用于后续下单。


    4. 填写收货信息并提交订单

    data = {
        'shipping_address': '123 Main St, City, Country',
        'email': 'anthonyle138@gmail.com',
        'payment_method': '1',  # 支付方式 ID
        'coupon_code': '',  # 可选
        'is_guest': False,
        'user_id': 'your_user_id'
    }
    
    response = requests.post('https://shopee.com/api/v4/checkout/submit', headers=headers, json=data)
    print(response.text)
    

    🔹 根据实际返回结果判断是否成功下单。


    📌 注意事项

    1. 确保 Cookie 和 Token 是最新的,否则请求会被拒绝。
    2. 建议使用代理 IP 和 User-Agent 轮换,防止被识别为机器人。
    3. 避免频繁请求,以免触发风控机制。
    4. 不要公开分享你的 Cookie 或 Token,这是敏感信息。

    🧪 示例代码(修改后)

    import requests
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
        'Cookie': 'skey=abc123; sid=xyz456; user_token=token123;',
        'X-XSRF-TOKEN': 'xsrf_token_here'
    }
    
    # Add to Cart
    add_to_cart_response = requests.post(
        'https://shopee.com/api/v4/cart/add',
        headers=headers,
        json={'item_id': '123456', 'variation_id': '0', 'quantity': '1'}
    )
    
    # Get Checkout Info
    checkout_info = requests.get('https://shopee.com/api/v4/checkout/get', headers=headers)
    
    # Submit Order
    order_data = {
        'shipping_address': '123 Main St, City, Country',
        'email': 'anthonyle138@gmail.com',
        'payment_method': '1'
    }
    order_response = requests.post('https://shopee.com/api/v4/checkout/submit', headers=headers, json=order_data)
    
    print("Add to Cart Response:", add_to_cart_response.text)
    print("Checkout Info:", checkout_info.text)
    print("Order Submission:", order_response.text)
    

    🚨 最后提醒

    • 自动化操作风险高,请谨慎使用。
    • 若你是想进行商品抢购,可以考虑使用更高级的工具如 Selenium + Puppeteer 来模拟真实用户行为。
    • 如需进一步帮助,欢迎提供具体错误信息或截图。

    如果你有更多细节(如商品 ID、支付方式等),我可以帮你进一步优化代码。

    评论

报告相同问题?

问题事件

  • 创建了问题 8月29日