> 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/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/selenium.md).

# Selenium

使用 Selenium 可以通过 [IPWO 代理](https://www.ipwo.net/)驱动真实浏览器，适用于自动化测试、网页操作与浏览器采集场景。

***

### 一、安装 Selenium

```bash
pip install selenium
```

***

### 二、Chrome 代理示例

```python
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

proxy = "http://username_custom_zone_US:password@us.ipwo.net:7878"

chrome_options = Options()

chrome_options.add_argument(f'--proxy-server={proxy}')

driver = webdriver.Chrome(
    options=chrome_options
)

driver.get("http://ipinfo.io")

print(driver.page_source)
```

***

### 三、验证代理是否生效

打开：

```
http://ipinfo.io
```

如果显示：

* 新 IP
* 对应国家地区

说明代理已经成功生效。

***

### 四、推荐使用场景

适用于：

* TikTok 自动化
* Facebook 操作
* Amazon 店铺管理
* 浏览器采集
* 自动化测试

***

### 五、常见问题

#### [IP 未生效](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/ip-bu-sheng-xiao.md)

请检查：

* 是否正确添加 `--proxy-server`
* 浏览器是否真正走代理

***

#### [浏览器检测失败](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/liu-lan-qi-jian-ce-shi-bai.md)

部分网站会检测：

* WebRTC
* 浏览器指纹
* 自动化特征

建议：

* 配合指纹浏览器使用
* 使用住宅代理
* 保持时区与 IP 一致

***

#### [Timeout 超时](/kai-fa-zhe-wen-dang/chang-jian-cuo-wu/chao-shi-timeout.md)

通常是：

* 网络环境异常
* 浏览器加载过慢
* 节点波动

***

### 六、推荐开发建议

推荐：

* 使用海外 VPS
* 使用住宅代理
* 一账号一 IP
* 使用粘性 Session

避免：

* 高频批量操作
* 多账号共用 IP

***

### 七、相关文章

* [Playwright](broken://pages/pKlFYj1SUTGIhRQK221q)
* [Puppeteer](broken://pages/Fz2QwhsUVkt1yG1tiTLN)
* [浏览器指纹检测](/dai-li-jian-ce-yu-yin-si-an-quan/liu-lan-qi-zhi-wen-jian-ce.md)
* [WebRTC 泄露检测](/dai-li-jian-ce-yu-yin-si-an-quan/webrtc-xie-lou-jian-ce.md)
* [如何降低账号关联风险](/dai-li-jian-ce-yu-yin-si-an-quan/ru-he-jiang-di-zhang-hao-guan-lian-feng-xian.md)
* [什么是粘性会话](/dai-li-ji-chu-zhi-shi/shen-me-shi-nian-xing-hui-hua.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/kai-fa-zhe-wen-dang/dai-ma-shi-li/python/selenium.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.
