docs: update README

This commit is contained in:
程序员阿江(Relakkes)
2025-11-22 08:20:09 +08:00
parent 13d2302c9c
commit 422cc92dd1
2 changed files with 65 additions and 43 deletions

View File

@@ -163,7 +163,7 @@ uv run main.py --help
cd MediaCrawler cd MediaCrawler
# 创建虚拟环境 # 创建虚拟环境
# 我的 python 版本是3.9.6requirements.txt 中的库是基于这个版本的 # 我的 python 版本是3.11 requirements.txt 中的库是基于这个版本的
# 如果是其他 python 版本,可能 requirements.txt 中的库不兼容,需自行解决 # 如果是其他 python 版本,可能 requirements.txt 中的库不兼容,需自行解决
python -m venv venv python -m venv venv

View File

@@ -1,52 +1,74 @@
## 使用python原生venv管理依赖不推荐了 # 本地原生环境管理
## 创建并激活 python 虚拟环境 ## 推荐方案:使用 uv 管理依赖
> 如果是爬取抖音和知乎需要提前安装nodejs环境版本大于等于`16`即可 <br>
> 新增 [uv](https://github.com/astral-sh/uv) 来管理项目依赖使用uv来替代python版本管理、pip进行依赖安装更加方便快捷
```shell
# 进入项目根目录
cd MediaCrawler
# 创建虚拟环境
# 我的python版本是3.9.6requirements.txt中的库是基于这个版本的如果是其他python版本可能requirements.txt中的库不兼容自行解决一下。
python -m venv venv
# macos & linux 激活虚拟环境
source venv/bin/activate
# windows 激活虚拟环境 ### 1. 前置依赖
venv\Scripts\activate - 安装 [uv](https://docs.astral.sh/uv/getting-started/installation),并使用 `uv --version` 验证。
- Python 版本建议使用 **3.11**(当前依赖基于该版本构建)。
- 安装 Node.js抖音、知乎等平台需要版本需 `>= 16.0.0`
``` ### 2. 同步 Python 依赖
```shell
# 进入项目根目录
cd MediaCrawler
## 安装依赖库 # 使用 uv 保证 Python 版本和依赖一致性
uv sync
```
```shell ### 3. 安装 Playwright 浏览器驱动
pip install -r requirements.txt ```shell
``` uv run playwright install
```
> 项目已支持使用 Playwright 连接本地 Chrome。如需使用 CDP 方式,可在 `config/base_config.py` 中调整 `xhs` 和 `dy` 的相关配置。
## 查看配置文件 ### 4. 运行爬虫程序
```shell
# 项目默认未开启评论爬取,如需评论请在 config/base_config.py 中修改 ENABLE_GET_COMMENTS
# 其他功能开关也可在 config/base_config.py 查看,均有中文注释
## 安装 playwright浏览器驱动 (非必需) # 从配置中读取关键词搜索并爬取帖子与评论
uv run main.py --platform xhs --lt qrcode --type search
```shell # 从配置中读取指定帖子ID列表并爬取帖子与评论
playwright install uv run main.py --platform xhs --lt qrcode --type detail
```
## 运行爬虫程序 # 其他平台示例
uv run main.py --help
```
```shell ## 备选方案Python 原生 venv不推荐
### 项目默认是没有开启评论爬取模式如需评论请在config/base_config.py中的 ENABLE_GET_COMMENTS 变量修改
### 一些其他支持项也可以在config/base_config.py查看功能写的有中文注释 ### 创建并激活虚拟环境
> 如果爬取抖音或知乎,需要提前安装 Node.js版本 `>= 16`。
# 从配置文件中读取关键词搜索相关的帖子并爬取帖子信息与评论 ```shell
python main.py --platform xhs --lt qrcode --type search # 进入项目根目录
cd MediaCrawler
# 从配置文件中读取指定的帖子ID列表获取指定帖子的信息与评论信息
python main.py --platform xhs --lt qrcode --type detail # 创建虚拟环境(示例 Python 版本3.11requirements 基于该版本)
python -m venv venv
# 打开对应APP扫二维码登录
# macOS & Linux 激活虚拟环境
# 其他平台爬虫使用示例,执行下面的命令查看 source venv/bin/activate
python main.py --help
``` # Windows 激活虚拟环境
venv\Scripts\activate
```
### 安装依赖与驱动
```shell
pip install -r requirements.txt
playwright install
```
### 运行爬虫程序venv 环境)
```shell
# 从配置中读取关键词搜索并爬取帖子与评论
python main.py --platform xhs --lt qrcode --type search
# 从配置中读取指定帖子ID列表并爬取帖子与评论
python main.py --platform xhs --lt qrcode --type detail
# 更多示例
python main.py --help
```