feat: 初次提交
This commit is contained in:
parent
4eb1564b91
commit
88fd31e101
84
README.md
84
README.md
@ -1,4 +1,80 @@
|
||||
### 创建虚拟环境
|
||||
python3 -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
|
||||
### 安装依赖
|
||||
pip install -r requirements.txt
|
||||
# Cookie 和链接数据采集工具
|
||||
|
||||
## 项目简介
|
||||
本项目是一个基于 Python 的网页数据采集工具,功能包括:
|
||||
- 抓取指定网页的所有链接 (`<a>` 标签的 `href`) 和 Cookie。
|
||||
- 截取页面截图并保存。
|
||||
- 生成包含链接、截图和 Cookie 文件信息的 Excel 报表。
|
||||
|
||||
---
|
||||
|
||||
## 环境要求
|
||||
- **Python 版本**:3.7+
|
||||
- **浏览器驱动**:`chromedriver`,需与 Chrome 浏览器版本匹配。
|
||||
- **操作系统**:支持 macOS、Linux 和 Windows。
|
||||
## 安装 `chromedriver` 并配置路径
|
||||
|
||||
### 1. 安装 **Homebrew**
|
||||
#### 首先,确保你已经安装了 **Homebrew**。如果没有安装,可以通过以下命令进行安装:
|
||||
```bash
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
```
|
||||
|
||||
### 2. 通过 Homebrew 安装 chromedriver
|
||||
|
||||
安装完成 Homebrew 后,使用以下命令通过 Homebrew 安装 chromedriver:
|
||||
|
||||
```bash
|
||||
brew install chromedriver
|
||||
```
|
||||
|
||||
### 3. 确认 chromedriver 安装路径
|
||||
安装完成后,chromedriver 会自动放置在 Homebrew 默认的可执行文件路径中,通常是 /opt/homebrew/bin/(对于 M1 或 M2 芯片的 Mac)。你可以通过以下命令确认安装位置:
|
||||
```bash
|
||||
which chromedriver
|
||||
```
|
||||
该命令会返回 chromedriver 的完整路径,例如:/opt/homebrew/bin/chromedriver。
|
||||
|
||||
### 4. 确认 chromedriver 安装路径
|
||||
安装完成后,代码中无需手动指定 chromedriver 的路径。只需在 Service 中使用默认路径即可:
|
||||
|
||||
```bash
|
||||
from selenium.webdriver.chrome.service import Service
|
||||
service = Service(executable_path='/opt/homebrew/bin/chromedriver')
|
||||
```
|
||||
|
||||
|
||||
|
||||
## 设置虚拟环境
|
||||
|
||||
### 1. 创建虚拟环境
|
||||
|
||||
为了确保项目的依赖包与系统的其他 Python 包不冲突,推荐使用虚拟环境。以下是如何创建虚拟环境的步骤。
|
||||
|
||||
#### 在 macOS 或 Linux 上:
|
||||
1. 打开终端。
|
||||
2. 进入你的项目目录。
|
||||
3. 创建虚拟环境:
|
||||
|
||||
```bash
|
||||
python3 -m venv venv
|
||||
```
|
||||
4. 激活虚拟环境:
|
||||
|
||||
```bash
|
||||
source venv/bin/activate
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 2. 依赖安装
|
||||
在运行代码之前,需安装项目依赖的 Python 库:
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### 3. 执行代码
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user