> For the complete documentation index, see [llms.txt](https://docs.ipwo.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ipwo.net/dai-li-ji-chu-zhi-shi/api-diao-yong-yu-pi-liang-cai-ji.md).

# API 调用与批量采集

在[数据采集](/ying-yong-chang-jing/shu-ju-cai-ji.md)场景中，除了浏览器方式外，更高效的方式是：

👉 使用 API + 代理进行批量请求

这种方式适用于高并发、自动化、长期运行的任务。

***

### 🌍 一、什么是 API 代理调用？

API 调用代理的本质是：

```
程序 → 代理服务器 → 目标网站
```

你不直接访问目标网站，而是通过代理“转发请求”。

***

### ⚙️ 二、为什么要结合 API + 代理？

直接调用 API / 网站时可能会遇到：

* IP 被限制
* 请求频率过高被封
* 返回验证码 / 403
* 数据不完整

👉 使用代理可以解决这些问题。

***

### 🔄 三、批量采集的基本结构

典型架构如下：

```
程序（Python / Node.js）
↓
代理池（IPWO）
↓
目标网站 / API
```

***

### 🚀 四、基础 API + 代理请求方式

***

#### 🐍 Python requests 示例

```python
import requests

proxies = {
    "http": "http://username:password@us.ipwo.net:7878",
    "https": "http://username:password@us.ipwo.net:7878"
}

response = requests.get(
    "https://api.ipify.org",
    proxies=proxies,
    timeout=10
)

print(response.text)
```

***

#### ⚡ cURL 批量测试示例

```bash
curl -x "http://username:password@us.ipwo.net:7878" https://ipinfo.io
```

***

### 🔁 五、批量采集的核心逻辑

批量采集通常包含：

```
循环请求 + 代理切换 + 数据存储
```

***

#### ✔ 示例流程：

1. 准备 URL 列表
2. 分配代理 IP
3. 发起请求
4. 获取数据
5. 存储结果
6. 重复执行

***

### 🌐 六、如何实现“自动换 IP”

IPWO 支持：

* [轮换 IP](/huo-qu-yu-pei-zhi-dai-li/lun-huan-ip.md)（每次请求自动换）
* [粘性 IP](/huo-qu-yu-pei-zhi-dai-li/nian-xing-ip.md)（短时间保持不变）

***

#### ✔ 轮换模式（推荐采集）

```
每次请求 → 自动分配新 IP
```

适合：

* [大规模抓取](/ying-yong-chang-jing/shu-ju-cai-ji.md)
* SEO 数据
* [AI 数据训练](/ying-yong-chang-jing/ai-shu-ju-xun-lian.md)

***

#### 📌 粘性模式（低频采集）

```
同一 Session → 保持同一 IP
```

适合：

* 需要登录状态的网站
* 分页抓取
* 会话型请求

***

### ⚙️ 七、批量采集优化策略

***

#### 1️⃣ 控制请求频率

```
建议：1–3 秒 / 请求
```

避免：

* 高频瞬间请求
* 并发过高

***

#### 2️⃣ 使用多 IP 分散请求

```
任务 → 多个代理 IP → 分散访问
```

***

#### 3️⃣ 设置超时机制

```python
timeout=10
```

避免卡死任务。

***

#### 4️⃣ 自动重试机制

失败请求建议：

* 更换 IP
* 重试 1–3 次

***

### 📊 八、批量采集典型场景

| 场景       | 说明                 |
| -------- | ------------------ |
| 电商价格采集   | Amazon / Shopify   |
| SEO 数据分析 | Google / Bing      |
| 社媒数据分析   | TikTok / Instagram |
| AI 数据训练  | 文本 / 图片抓取          |
| 竞品监控     | 商品 / 广告数据          |

***

### 🔒 九、如何降低封禁风险（关键）

结合 API + 代理时必须注意：

***

#### ✔ 推荐策略：

```
低频请求 + IP轮换 + 行为模拟
```

***

#### ❌ 避免：

* 单 IP 高频请求
* 同一 URL 重复抓取
* 无间隔并发请求

***

### 🧠 十、进阶：代理池思路

当数据量较大时，可以构建：

```
代理池 = 多 IP + 自动轮换 + 健康检测
```

***

结构：

* IPWO 提供代理
* 程序自动调用
* 失败自动剔除 IP
* 成功继续使用

***

### ⚡ 十一、快速测试 API 是否正常

```bash
curl -x "http://username:password@us.ipwo.net:7878" https://api.ipify.org
```

***

### 🚀 总结

API + 代理批量采集的核心是：

```
程序自动化 + IP分发 + 请求控制
```

***

#### ✔ 最佳实践：

* 使用轮换 IP 做大规模采集
* 使用粘性 IP 做登录型任务
* 控制请求频率
* 加入重试机制

***

👉 合理使用代理 API，可以显著提升采集效率并降低封禁风险


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.ipwo.net/dai-li-ji-chu-zhi-shi/api-diao-yong-yu-pi-liang-cai-ji.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
