Skip to content

Commit 1da347c

Browse files
committed
docs: update index.md
1 parent 422cc92 commit 1da347c

File tree

1 file changed

+71
-54
lines changed

1 file changed

+71
-54
lines changed

docs/index.md

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,76 @@
11
# MediaCrawler使用方法
22

3-
## 创建并激活 python 虚拟环境
4-
> 如果是爬取抖音和知乎,需要提前安装nodejs环境,版本大于等于:`16`即可 <br>
5-
```shell
6-
# 进入项目根目录
7-
cd MediaCrawler
8-
9-
# 创建虚拟环境
10-
# 我的python版本是:3.9.6,requirements.txt中的库是基于这个版本的,如果是其他python版本,可能requirements.txt中的库不兼容,自行解决一下。
11-
python -m venv venv
12-
13-
# macos & linux 激活虚拟环境
14-
source venv/bin/activate
15-
16-
# windows 激活虚拟环境
17-
venv\Scripts\activate
18-
19-
```
20-
21-
## 安装依赖库
22-
23-
```shell
24-
pip install -r requirements.txt
25-
```
26-
27-
## 安装 playwright浏览器驱动
28-
29-
```shell
30-
playwright install
31-
```
32-
33-
## 运行爬虫程序
34-
35-
```shell
36-
### 项目默认是没有开启评论爬取模式,如需评论请在config/base_config.py中的 ENABLE_GET_COMMENTS 变量修改
37-
### 一些其他支持项,也可以在config/base_config.py查看功能,写的有中文注释
38-
39-
# 从配置文件中读取关键词搜索相关的帖子并爬取帖子信息与评论
40-
python main.py --platform xhs --lt qrcode --type search
41-
42-
# 从配置文件中读取指定的帖子ID列表获取指定帖子的信息与评论信息
43-
python main.py --platform xhs --lt qrcode --type detail
44-
45-
# 使用SQLite数据库存储数据(推荐个人用户使用)
46-
python main.py --platform xhs --lt qrcode --type search --save_data_option sqlite
47-
48-
# 使用MySQL数据库存储数据
49-
python main.py --platform xhs --lt qrcode --type search --save_data_option db
50-
51-
# 打开对应APP扫二维码登录
52-
53-
# 其他平台爬虫使用示例,执行下面的命令查看
54-
python main.py --help
55-
```
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+
# 使用 SQLite 数据库存储数据(推荐个人用户使用)
37+
uv run main.py --platform xhs --lt qrcode --type search --save_data_option sqlite
38+
39+
# 使用 MySQL 数据库存储数据
40+
uv run main.py --platform xhs --lt qrcode --type search --save_data_option db
41+
42+
# 其他平台示例
43+
uv run main.py --help
44+
```
45+
46+
## 备选:Python 原生 venv(不推荐)
47+
> 如果爬取抖音或知乎,需要提前安装 Node.js,版本 `>= 16`
48+
```shell
49+
# 进入项目根目录
50+
cd MediaCrawler
51+
52+
# 创建虚拟环境(示例 Python 版本:3.11,requirements 基于该版本)
53+
python -m venv venv
54+
55+
# macOS & Linux 激活虚拟环境
56+
source venv/bin/activate
57+
58+
# Windows 激活虚拟环境
59+
venv\Scripts\activate
60+
```
61+
```shell
62+
# 安装依赖与驱动
63+
pip install -r requirements.txt
64+
playwright install
65+
```
66+
```shell
67+
# 运行爬虫程序(venv 环境)
68+
python main.py --platform xhs --lt qrcode --type search
69+
python main.py --platform xhs --lt qrcode --type detail
70+
python main.py --platform xhs --lt qrcode --type search --save_data_option sqlite
71+
python main.py --platform xhs --lt qrcode --type search --save_data_option db
72+
python main.py --help
73+
```
5674

5775
## 💾 数据存储
5876

@@ -74,4 +92,3 @@
7492
> 大家请以学习为目的使用本仓库,爬虫违法违规的案件:https://github.com/HiddenStrawberry/Crawler_Illegal_Cases_In_China <br>
7593
>
7694
>本项目的所有内容仅供学习和参考之用,禁止用于商业用途。任何人或组织不得将本仓库的内容用于非法用途或侵犯他人合法权益。本仓库所涉及的爬虫技术仅用于学习和研究,不得用于对其他平台进行大规模爬虫或其他非法行为。对于因使用本仓库内容而引起的任何法律责任,本仓库不承担任何责任。使用本仓库的内容即表示您同意本免责声明的所有条款和条件。
77-

0 commit comments

Comments
 (0)