Files
paste-framework/examples/12_batch_api_calls/README.md
T
2026-06-02 16:30:48 +08:00

967 B
Raw Blame History

批量接口调用范例

flowchart TD
    subgraph 真实场景
        S1["爬虫<br/>1000个页面"]
        S2["批量下单<br/>500个订单"]
        S3["数据同步<br/>5个系统"]
        S4["压测<br/>自己服务器"]
    end
    
    subgraph Paste方案
        P1["new_http_request × N"]
        P2["async_concurrency 一发"]
        P3["统一处理响应"]
    end
    
    S1 --> P1 --> P2 --> P3
    S2 --> P1 --> P2 --> P3
    S3 --> P1 --> P2 --> P3
    S4 --> P1 --> P2 --> P3

支持的能力

  • GET / POST / JSON / Form / 文件上传
  • 自动随机 User-Agent
  • 自动提取 Cookie
  • 批量并发控制
  • 自动重试
  • 统一响应/错误处理

代码量

  • Java: 200-300 行
  • Paste: 20 行

示例

# 准备1000个请求
for i in range(1000):
    req = new_http_request(url, method="POST", body={"id": i})
    await queue.put(req)

# 批量发出
await async_concurrency(queue, con_count=50)