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