# Selenium Install

## Target

成功安装并使用 Selenium (Windows)

## Details

1. 安装 Selenium 包  &#x20;

   ```bash
   (sudo) pip install selenium
   ```
2. 安装 chromedriver  &#x20;
   1. **前置条件**：安装 Chrome 浏览器 &#x20;
   2. chromedriver 是一个自动控制 chrome 浏览器的软件，可以实现爬虫和脚本运行 &#x20;
   3. 查看 Chrome 版本：在 Chrome 的网址栏输入 `chrome://version`，得到的界面第一行就是版本号，如我的版本号：`Google Chrome    80.0.3987.116 (正式版本) （32 位） (cohort: 80_87_Win)`，只需要版本号的前三位 `80.0.3987`  &#x20;
   4. 前往下载地址根据自己的版本号下载对应的版本：[下载地址1](http://chromedriver.storage.googleapis.com/index.html) [下载地址2](https://npm.taobao.org/mirrors/chromedriver/) &#x20;
   5. 解压下载好的 chromedriver.exe，将其放到 chrome.exe 的同根目录下，具体的 chrome.exe 的位置可以通过右键 chrome 的图标->属性->目标 找到，一般位于 `C:\Program Files (x86)\Google\Chrome\Application\` 下  &#x20;
   6. 将上面存放 chrome.exe 的目录加入到环境变量 PATH 中  &#x20;
   7. 启动 cmd 输入 chromedriver 是否报错，未报错则说明成功  &#x20;
3. python 测试 chromedriver

   ```python
    from selenium import webdriver
    import time

    def main():
        b = webdriver.Chrome()
        b.get('https://www.baidu.com')
        time.sleep(5)
        b.quit()

    if __name__ == '__main__':
        main()
   ```

   现象为 chrome 自动打卡并登陆百度，5s后正常关闭，整个过程未报错

## Reference

1. [selenium 安装与 chromedriver安装](https://www.cnblogs.com/lfri/p/10542797.html)


---

# Agent Instructions: 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:

```
GET https://legacy.cookielau.com/archives/3-python/3-spider/1-seleniuminstall.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
