> 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/ji-cheng-jiao-cheng/gong-ju-yu-dai-li-ruan-jian/ru-he-zai-puppeteer-zhong-shi-yong-ipwo-dai-li.md).

# 如何在 Puppeteer 中使用 IPWO 代理

Puppeteer 是基于 Chromium 的浏览器自动化工具，广泛用于跨境电商、社媒运营、自动化测试与数据采集等场景。

通过搭配 IPWO 住宅代理，可以为不同自动化任务分配独立网络环境，实现更稳定的海外业务访问体验。

本文将介绍如何在 Puppeteer 中配置 IPWO 代理，并验证代理是否生效。

***

### 准备工作

开始前，请确保已经准备好以下内容：

* Node.js 环境
* Puppeteer
* IPWO 代理信息

需要提前从 IPWO 后台获取：

* 代理 IP
* 端口
* 用户名
* 密码

👉 请参考：

* 「[如何获取代理](https://docs.ipwo.net/huo-qu-yu-pei-zhi-dai-li/ru-he-huo-qu-dai-li)」→ 获取完整代理信息
* 「[用户名 & 密码认证](https://docs.ipwo.net/huo-qu-yu-pei-zhi-dai-li/ru-he-huo-qu-dai-li/yong-hu-ming-he-mi-ma-ren-zheng)」→ 查看账密使用方式

👉 动态住宅代理支持参数配置（如地区 / session），可参考「[参数说明](https://docs.ipwo.net/huo-qu-yu-pei-zhi-dai-li/can-shu-shuo-ming)」

***

### 安装 Puppeteer

打开终端或命令行工具，运行以下命令安装 Puppeteer：

```
npm init -ynpm install puppeteer
```

***

### 配置 IPWO HTTP 代理

创建一个文件，例如：

```
puppeteer_ipwo_proxy.js
```

将以下代码复制进去：

```
const puppeteer = require('puppeteer');(async () => {  // IPWO 代理信息  const proxyHost = 'gate.ipwo.net';  const proxyPort = '端口';  const proxyUser = '用户名';  const proxyPass = '密码';  // 启动浏览器  const browser = await puppeteer.launch({    headless: false,    args: [      `--proxy-server=http://${proxyHost}:${proxyPort}`    ]  });  const page = await browser.newPage();  // 设置代理认证  await page.authenticate({    username: proxyUser,    password: proxyPass  });  // 打开 IP 检测页面  await page.goto('https://ipinfo.io');  console.log('代理已连接');})();
```

***

### 运行代码

在终端执行：

```
node puppeteer_ipwo_proxy.js
```

运行后，浏览器会自动打开 IP 检测页面。

如果显示的 IP 与 IPWO 提供的代理 IP 一致，则说明代理配置成功。

***

### 配置 SOCKS5 代理（可选）

如果使用的是 SOCKS5 类型代理，可将代理参数修改为：

```
args: [  `--proxy-server=socks5://${proxyHost}:${proxyPort}`]
```

完整示例：

```
const puppeteer = require('puppeteer');(async () => {  const browser = await puppeteer.launch({    headless: false,    args: [      '--proxy-server=socks5://gate.ipwo.net:端口'    ]  });  const page = await browser.newPage();  await page.authenticate({    username: '用户名',    password: '密码'  });  await page.goto('https://ipinfo.io');})();
```

***

### 常见问题

#### Puppeteer 无法启动浏览器

请检查：

* Node.js 是否安装成功
* Puppeteer 是否正确安装
* 本地 Chromium 是否下载完成

***

#### 代理连接失败

请确认：

* 代理 IP 与端口填写正确
* 用户名与密码无误
* 当前代理套餐仍处于有效状态

***

#### 为什么访问速度较慢？

代理速度可能受到以下因素影响：

* 节点地区
* 本地网络环境
* 当前目标网站负载情况

建议：

* 更换国家节点
* 使用 Sticky Session
* 检查本地网络连接

***

### 适用场景

IPWO 与 Puppeteer 的组合适用于：

| 场景     | 说明      |
| ------ | ------- |
| 跨境电商   | 多地区业务访问 |
| 社媒运营   | 多账号环境管理 |
| 自动化测试  | 海外业务测试  |
| 数据采集   | 稳定网络环境  |
| 浏览器自动化 | 自动化访问流程 |

***

### 相关推荐

* [如何在 Selenium 中使用 IPWO 代理](/ji-cheng-jiao-cheng/gong-ju-yu-dai-li-ruan-jian/ru-he-zai-selenium-zhong-shi-yong-ipwo-dai-li.md)
* [如何在 Playwright 中使用 IPWO 代理](/ji-cheng-jiao-cheng/gong-ju-yu-dai-li-ruan-jian/ru-he-zai-playwright-zhong-shi-yong-ipwo-dai-li.md)


---

# 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/ji-cheng-jiao-cheng/gong-ju-yu-dai-li-ruan-jian/ru-he-zai-puppeteer-zhong-shi-yong-ipwo-dai-li.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.
