Skip to content

Commit 422cc92

Browse files
committed
docs: update README
1 parent 13d2302 commit 422cc92

File tree

2 files changed

+75
-53
lines changed

2 files changed

+75
-53
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ uv run main.py --help
163163
cd MediaCrawler
164164

165165
# 创建虚拟环境
166-
# 我的 python 版本是:3.9.6,requirements.txt 中的库是基于这个版本的
166+
# 我的 python 版本是:3.11 requirements.txt 中的库是基于这个版本的
167167
# 如果是其他 python 版本,可能 requirements.txt 中的库不兼容,需自行解决
168168
python -m venv venv
169169

docs/原生环境管理文档.md

Lines changed: 74 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,74 @@
1-
## 使用python原生venv管理依赖(不推荐了)
2-
3-
## 创建并激活 python 虚拟环境
4-
> 如果是爬取抖音和知乎,需要提前安装nodejs环境,版本大于等于:`16`即可 <br>
5-
> 新增 [uv](https://github.com/astral-sh/uv) 来管理项目依赖,使用uv来替代python版本管理、pip进行依赖安装,更加方便快捷
6-
```shell
7-
# 进入项目根目录
8-
cd MediaCrawler
9-
10-
# 创建虚拟环境
11-
# 我的python版本是:3.9.6,requirements.txt中的库是基于这个版本的,如果是其他python版本,可能requirements.txt中的库不兼容,自行解决一下。
12-
python -m venv venv
13-
14-
# macos & linux 激活虚拟环境
15-
source venv/bin/activate
16-
17-
# windows 激活虚拟环境
18-
venv\Scripts\activate
19-
20-
```
21-
22-
## 安装依赖库
23-
24-
```shell
25-
pip install -r requirements.txt
26-
```
27-
28-
## 查看配置文件
29-
30-
## 安装 playwright浏览器驱动 (非必需)
31-
32-
```shell
33-
playwright install
34-
```
35-
36-
## 运行爬虫程序
37-
38-
```shell
39-
### 项目默认是没有开启评论爬取模式,如需评论请在config/base_config.py中的 ENABLE_GET_COMMENTS 变量修改
40-
### 一些其他支持项,也可以在config/base_config.py查看功能,写的有中文注释
41-
42-
# 从配置文件中读取关键词搜索相关的帖子并爬取帖子信息与评论
43-
python main.py --platform xhs --lt qrcode --type search
44-
45-
# 从配置文件中读取指定的帖子ID列表获取指定帖子的信息与评论信息
46-
python main.py --platform xhs --lt qrcode --type detail
47-
48-
# 打开对应APP扫二维码登录
49-
50-
# 其他平台爬虫使用示例,执行下面的命令查看
51-
python main.py --help
52-
```
1+
# 本地原生环境管理
2+
3+
## 推荐方案:使用 uv 管理依赖
4+
5+
### 1. 前置依赖
6+
- 安装 [uv](https://docs.astral.sh/uv/getting-started/installation),并使用 `uv --version` 验证。
7+
- Python 版本建议使用 **3.11**(当前依赖基于该版本构建)。
8+
- 安装 Node.js(抖音、知乎等平台需要),版本需 `>= 16.0.0`
9+
10+
### 2. 同步 Python 依赖
11+
```shell
12+
# 进入项目根目录
13+
cd MediaCrawler
14+
15+
# 使用 uv 保证 Python 版本和依赖一致性
16+
uv sync
17+
```
18+
19+
### 3. 安装 Playwright 浏览器驱动
20+
```shell
21+
uv run playwright install
22+
```
23+
> 项目已支持使用 Playwright 连接本地 Chrome。如需使用 CDP 方式,可在 `config/base_config.py` 中调整 `xhs``dy` 的相关配置。
24+
25+
### 4. 运行爬虫程序
26+
```shell
27+
# 项目默认未开启评论爬取,如需评论请在 config/base_config.py 中修改 ENABLE_GET_COMMENTS
28+
# 其他功能开关也可在 config/base_config.py 查看,均有中文注释
29+
30+
# 从配置中读取关键词搜索并爬取帖子与评论
31+
uv run main.py --platform xhs --lt qrcode --type search
32+
33+
# 从配置中读取指定帖子ID列表并爬取帖子与评论
34+
uv run main.py --platform xhs --lt qrcode --type detail
35+
36+
# 其他平台示例
37+
uv run main.py --help
38+
```
39+
40+
## 备选方案:Python 原生 venv(不推荐)
41+
42+
### 创建并激活虚拟环境
43+
> 如果爬取抖音或知乎,需要提前安装 Node.js,版本 `>= 16`
44+
```shell
45+
# 进入项目根目录
46+
cd MediaCrawler
47+
48+
# 创建虚拟环境(示例 Python 版本:3.11,requirements 基于该版本)
49+
python -m venv venv
50+
51+
# macOS & Linux 激活虚拟环境
52+
source venv/bin/activate
53+
54+
# Windows 激活虚拟环境
55+
venv\Scripts\activate
56+
```
57+
58+
### 安装依赖与驱动
59+
```shell
60+
pip install -r requirements.txt
61+
playwright install
62+
```
63+
64+
### 运行爬虫程序(venv 环境)
65+
```shell
66+
# 从配置中读取关键词搜索并爬取帖子与评论
67+
python main.py --platform xhs --lt qrcode --type search
68+
69+
# 从配置中读取指定帖子ID列表并爬取帖子与评论
70+
python main.py --platform xhs --lt qrcode --type detail
71+
72+
# 更多示例
73+
python main.py --help
74+
```

0 commit comments

Comments
 (0)