优化修改文件
This commit is contained in:
parent
aacedf14fe
commit
8d4369ecef
@ -1,37 +0,0 @@
|
|||||||
# Chrome Profile Setup Guide
|
|
||||||
|
|
||||||
## 重要说明
|
|
||||||
|
|
||||||
Chrome 配置文件 (`scripts/config/chrome_profile/douyin_persistent`) 包含大量缓存文件和个人登录信息,这些文件不应该加入 Git 版本控制。
|
|
||||||
|
|
||||||
## 手动设置步骤
|
|
||||||
|
|
||||||
1. **创建 Chrome 配置文件目录**
|
|
||||||
```bash
|
|
||||||
mkdir -p scripts/config/chrome_profile/douyin_persistent
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **手动登录抖音**
|
|
||||||
- 运行 `scripts/douyin_selenium_cdp_play_vv.py` 脚本
|
|
||||||
- 首次运行时会自动创建 Chrome 配置文件
|
|
||||||
- 在浏览器中手动登录抖音账号
|
|
||||||
- 登录成功后关闭浏览器
|
|
||||||
|
|
||||||
3. **验证登录状态**
|
|
||||||
- 重新运行脚本
|
|
||||||
- 如果能够正常获取数据,说明登录状态已保存
|
|
||||||
|
|
||||||
## 为什么 Chrome 配置文件不加入 Git
|
|
||||||
|
|
||||||
- **文件大小**: Chrome 配置文件包含大量缓存文件,总大小可能超过 100MB
|
|
||||||
- **个人隐私**: 包含登录凭据、Cookie 等敏感信息
|
|
||||||
- **平台差异**: 不同操作系统上的 Chrome 配置文件不兼容
|
|
||||||
- **动态变化**: 缓存文件会频繁变化,不适合版本控制
|
|
||||||
|
|
||||||
## 故障排除
|
|
||||||
|
|
||||||
如果登录状态丢失,请重新执行手动登录步骤。
|
|
||||||
|
|
||||||
## 驱动程序
|
|
||||||
|
|
||||||
ChromeDriver (`drivers/chromedriver.exe`) 已包含在 Git 仓库中,无需额外设置。
|
|
||||||
133
README_定时器.md
133
README_定时器.md
@ -1,133 +0,0 @@
|
|||||||
# 抖音播放量自动抓取定时器 - 跨平台版本
|
|
||||||
|
|
||||||
## 🎯 概述
|
|
||||||
|
|
||||||
这是一个跨平台的Python定时器,可以在任何电脑上运行,自动在每晚22:00执行抖音播放量抓取任务。
|
|
||||||
|
|
||||||
## 📋 支持平台
|
|
||||||
|
|
||||||
- ✅ **Windows** (Windows 10/11)
|
|
||||||
- ✅ **macOS** (Intel/Apple Silicon)
|
|
||||||
- ✅ **Linux** (Ubuntu/CentOS等)
|
|
||||||
|
|
||||||
## 🚀 快速开始
|
|
||||||
|
|
||||||
### 1. 安装依赖
|
|
||||||
```bash
|
|
||||||
pip install -r config/requirements.txt
|
|
||||||
pip install schedule
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 启动定时器
|
|
||||||
```bash
|
|
||||||
# 启动定时器
|
|
||||||
python douyin_auto_scheduler.py
|
|
||||||
|
|
||||||
# 测试模式(立即执行一次)
|
|
||||||
python douyin_auto_scheduler.py --test
|
|
||||||
|
|
||||||
# 只执行一次
|
|
||||||
python douyin_auto_scheduler.py --once
|
|
||||||
|
|
||||||
# 显示帮助
|
|
||||||
python douyin_auto_scheduler.py --help
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 停止定时器
|
|
||||||
按 `Ctrl+C` 停止定时器
|
|
||||||
|
|
||||||
## 📁 文件说明
|
|
||||||
|
|
||||||
- `douyin_auto_scheduler.py` - 主定时器文件
|
|
||||||
- `start_scheduler.py` - 简化启动脚本
|
|
||||||
- `scripts/douyin_selenium_cdp_play_vv.py` - 抓取脚本
|
|
||||||
- `config/requirements.txt` - Python依赖
|
|
||||||
|
|
||||||
## ⚙️ 配置说明
|
|
||||||
|
|
||||||
### 执行时间
|
|
||||||
- **主执行时间**: 每晚 22:00
|
|
||||||
- **备用执行时间**: 每晚 22:05
|
|
||||||
|
|
||||||
### 日志文件
|
|
||||||
- 定时器日志: `logs/scheduler.log`
|
|
||||||
- 抓取任务日志: `logs/auto_update_YYYYMMDD.log`
|
|
||||||
|
|
||||||
## 🔧 使用方法
|
|
||||||
|
|
||||||
### macOS/Linux 后台运行
|
|
||||||
```bash
|
|
||||||
# 使用nohup在后台运行
|
|
||||||
nohup python douyin_auto_scheduler.py > scheduler.log 2>&1 &
|
|
||||||
|
|
||||||
# 查看进程
|
|
||||||
ps aux | grep douyin_auto_scheduler
|
|
||||||
|
|
||||||
# 停止进程
|
|
||||||
pkill -f douyin_auto_scheduler
|
|
||||||
```
|
|
||||||
|
|
||||||
### Windows 后台运行
|
|
||||||
```bash
|
|
||||||
# 使用start命令在后台运行
|
|
||||||
start /B python douyin_auto_scheduler.py
|
|
||||||
|
|
||||||
# 查看任务管理器中的Python进程
|
|
||||||
```
|
|
||||||
|
|
||||||
### 首次使用
|
|
||||||
1. 运行测试模式确保环境正常
|
|
||||||
2. 手动登录抖音账号保存登录状态
|
|
||||||
3. 启动定时器
|
|
||||||
|
|
||||||
## 🎯 功能特点
|
|
||||||
|
|
||||||
- ✅ **跨平台兼容** - 支持所有主流操作系统
|
|
||||||
- ✅ **自动执行** - 每晚22:00自动运行
|
|
||||||
- ✅ **状态监控** - 实时显示下次执行时间
|
|
||||||
- ✅ **错误恢复** - 自动重试机制
|
|
||||||
- ✅ **日志记录** - 详细的执行日志
|
|
||||||
- ✅ **数据库保存** - 自动保存到MongoDB
|
|
||||||
|
|
||||||
## 📞 故障排除
|
|
||||||
|
|
||||||
### 常见问题
|
|
||||||
|
|
||||||
1. **Python依赖问题**
|
|
||||||
```bash
|
|
||||||
pip install --upgrade pip
|
|
||||||
pip install -r config/requirements.txt
|
|
||||||
pip install schedule
|
|
||||||
```
|
|
||||||
|
|
||||||
2. **Chrome浏览器问题**
|
|
||||||
- 确保Chrome浏览器已安装
|
|
||||||
- 确保chromedriver可用
|
|
||||||
|
|
||||||
3. **MongoDB连接问题**
|
|
||||||
- 确保MongoDB服务运行
|
|
||||||
- 检查连接配置
|
|
||||||
|
|
||||||
4. **网络连接问题**
|
|
||||||
- 确保网络连接正常
|
|
||||||
- 检查防火墙设置
|
|
||||||
|
|
||||||
### 日志检查
|
|
||||||
```bash
|
|
||||||
# 查看定时器日志
|
|
||||||
tail -f logs/scheduler.log
|
|
||||||
|
|
||||||
# 查看抓取任务日志
|
|
||||||
ls -la logs/auto_update_*.log
|
|
||||||
```
|
|
||||||
|
|
||||||
## 💡 提示
|
|
||||||
|
|
||||||
- 首次使用建议先运行测试模式
|
|
||||||
- 确保计算机在22:00处于开机状态
|
|
||||||
- 定期检查日志文件确认任务正常执行
|
|
||||||
- 如需修改执行时间,编辑 `douyin_auto_scheduler.py` 中的时间设置
|
|
||||||
|
|
||||||
## 🎉 完成设置
|
|
||||||
|
|
||||||
设置完成后,系统将在每晚22:00自动执行,无需手动操作!
|
|
||||||
395
docs/API接口文档.md
395
docs/API接口文档.md
@ -1,216 +1,289 @@
|
|||||||
# 抖音播放量数据API接口文档
|
# 小程序抖音播放量数据API文档
|
||||||
|
|
||||||
## 🚀 服务器信息
|
## 概述
|
||||||
|
|
||||||
- **服务器地址**: `http://localhost:5000` 或 `http://你的服务器IP:5000`
|
抖音短剧播放量数据API,专为小程序优化,支持分页、搜索、增长分析等功能。
|
||||||
- **协议**: HTTP
|
|
||||||
- **数据格式**: JSON
|
|
||||||
- **编码**: UTF-8
|
|
||||||
- **跨域支持**: 已配置CORS,支持小程序调用
|
|
||||||
|
|
||||||
## 📋 API接口列表
|
**服务地址**: `http://localhost:5001`
|
||||||
|
**启动命令**: `cd backend && python miniprogram_api_server.py`
|
||||||
|
|
||||||
### 1. 获取最新播放量数据
|
## 接口列表
|
||||||
|
|
||||||
**接口地址**: `GET /api/latest`
|
### 1. 健康检查
|
||||||
|
`GET /api/health`
|
||||||
|
- 检查服务器和数据库状态
|
||||||
|
|
||||||
**功能说明**: 获取最新一批的抖音剧本播放量数据,按排名排序
|
### 2. 视频列表
|
||||||
|
`GET /api/videos`
|
||||||
|
|
||||||
**请求参数**:
|
**参数**:
|
||||||
- `limit` (可选): 返回数据条数,默认50条
|
- `page`: 页码(默认1)
|
||||||
|
- `limit`: 每页数量(默认20,最大50)
|
||||||
|
- `sort`: 排序方式
|
||||||
|
- `playcount`: 按总播放量排序
|
||||||
|
- `growth`: 按增长排序
|
||||||
|
- `time`: 按时间排序
|
||||||
|
- `start_date`: 开始日期(增长排序用,格式:2025-10-16)
|
||||||
|
- `end_date`: 结束日期(增长排序用,格式:2025-10-17)
|
||||||
|
|
||||||
**请求示例**:
|
**示例**:
|
||||||
```
|
```
|
||||||
GET /api/latest?limit=10
|
# 总播放量排序
|
||||||
|
/api/videos?page=1&limit=10&sort=playcount
|
||||||
|
|
||||||
|
# 增长排序(昨天到今天)
|
||||||
|
/api/videos?page=1&limit=10&sort=growth
|
||||||
|
|
||||||
|
# 自定义日期增长排序
|
||||||
|
/api/videos?page=1&limit=10&sort=growth&start_date=2025-10-16&end_date=2025-10-17
|
||||||
```
|
```
|
||||||
|
|
||||||
**返回数据格式**:
|
### 3. 热门榜单
|
||||||
|
`GET /api/top`
|
||||||
|
- `limit`: 返回数量(默认10,最大50)
|
||||||
|
|
||||||
|
### 4. 搜索视频
|
||||||
|
`GET /api/search`
|
||||||
|
- `q`: 搜索关键词
|
||||||
|
- `page`: 页码
|
||||||
|
- `limit`: 每页数量
|
||||||
|
|
||||||
|
### 5. 视频详情
|
||||||
|
`GET /api/detail`
|
||||||
|
- `id`: 视频ID
|
||||||
|
|
||||||
|
## 数据字段说明
|
||||||
|
|
||||||
|
### 视频数据字段
|
||||||
|
- `_id`: 视频唯一ID
|
||||||
|
- `mix_name`: 短剧名称
|
||||||
|
- `playcount`: 播放量文本(如"2.1亿")
|
||||||
|
- `play_vv`: 播放量数值
|
||||||
|
- `video_url`: 抖音合集链接
|
||||||
|
- `rank`: 排名
|
||||||
|
- `batch_time`: 数据采集时间
|
||||||
|
- `aweme_ids`: 视频ID数组
|
||||||
|
- `cover_image_url`: 封面图片
|
||||||
|
- `cover_backup_urls`: 备用封面图片
|
||||||
|
- `request_id`: 请求ID
|
||||||
|
|
||||||
|
### 增长排序特有字段
|
||||||
|
- `growth`: 播放量增长值
|
||||||
|
- `start_date`: 开始日期
|
||||||
|
- `end_date`: 结束日期
|
||||||
|
|
||||||
|
## 响应格式
|
||||||
|
|
||||||
|
所有接口返回格式:
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"success": true,
|
"success": true/false,
|
||||||
"data": [
|
"data": [...],
|
||||||
{
|
"message": "错误信息(仅当success为false时)"
|
||||||
"rank": 1,
|
|
||||||
"script_name": "九尾狐男妖爱上我更新37集",
|
|
||||||
"playcount": "2.1亿",
|
|
||||||
"playcount_number": 210000000.0,
|
|
||||||
"update_time": "2025-10-15 18:39:29"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"total": 35,
|
|
||||||
"update_time": "2025-10-15 18:39:29"
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 2. 搜索剧本
|
视频列表接口额外包含:
|
||||||
|
- `pagination`: 分页信息
|
||||||
|
- `sort_by`: 排序方式
|
||||||
|
- `date_range`: 日期范围(仅增长排序)
|
||||||
|
- `update_time`: 更新时间
|
||||||
|
|
||||||
**接口地址**: `GET /api/search`
|
## 📱 小程序集成示例
|
||||||
|
|
||||||
**功能说明**: 根据剧本名称进行模糊搜索
|
### 微信小程序示例
|
||||||
|
|
||||||
**请求参数**:
|
|
||||||
- `name` (必需): 搜索关键词
|
|
||||||
|
|
||||||
**请求示例**:
|
|
||||||
```
|
|
||||||
GET /api/search?name=九尾狐
|
|
||||||
```
|
|
||||||
|
|
||||||
**返回数据格式**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"rank": 1,
|
|
||||||
"script_name": "九尾狐男妖爱上我更新37集",
|
|
||||||
"playcount": "2.1亿",
|
|
||||||
"playcount_number": 210000000.0,
|
|
||||||
"update_time": "2025-10-15 18:39:29"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"total": 1,
|
|
||||||
"search_keyword": "九尾狐"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 获取热门剧本
|
|
||||||
|
|
||||||
**接口地址**: `GET /api/top`
|
|
||||||
|
|
||||||
**功能说明**: 获取播放量最高的剧本列表
|
|
||||||
|
|
||||||
**请求参数**:
|
|
||||||
- `limit` (可选): 返回数据条数,默认10条
|
|
||||||
|
|
||||||
**请求示例**:
|
|
||||||
```
|
|
||||||
GET /api/top?limit=5
|
|
||||||
```
|
|
||||||
|
|
||||||
**返回数据格式**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"data": [
|
|
||||||
{
|
|
||||||
"rank": 1,
|
|
||||||
"script_name": "九尾狐男妖爱上我更新37集",
|
|
||||||
"playcount": "2.1亿",
|
|
||||||
"playcount_number": 210000000.0,
|
|
||||||
"update_time": "2025-10-15 18:39:29"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"total": 5
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 4. 服务器状态
|
|
||||||
|
|
||||||
**接口地址**: `GET /api/status`
|
|
||||||
|
|
||||||
**功能说明**: 获取API服务器和数据库状态
|
|
||||||
|
|
||||||
**请求示例**:
|
|
||||||
```
|
|
||||||
GET /api/status
|
|
||||||
```
|
|
||||||
|
|
||||||
**返回数据格式**:
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"success": true,
|
|
||||||
"mongodb_status": "连接正常",
|
|
||||||
"total_records": 35,
|
|
||||||
"latest_update": "2025-10-15 18:39:29",
|
|
||||||
"server_time": "2025-10-15 18:54:45"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📱 小程序调用示例
|
|
||||||
|
|
||||||
### 微信小程序示例代码
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// 获取最新数据
|
// 获取视频列表
|
||||||
wx.request({
|
wx.request({
|
||||||
url: 'http://你的服务器IP:5000/api/latest',
|
url: 'http://localhost:5001/api/videos',
|
||||||
method: 'GET',
|
|
||||||
data: {
|
data: {
|
||||||
limit: 20
|
page: 1,
|
||||||
|
limit: 10,
|
||||||
|
sort: 'playcount'
|
||||||
},
|
},
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
console.log('获取数据成功:', res.data);
|
|
||||||
if (res.data.success) {
|
if (res.data.success) {
|
||||||
// 处理数据
|
const videos = res.data.data;
|
||||||
const scripts = res.data.data;
|
videos.forEach(video => {
|
||||||
// 更新页面数据
|
console.log(`${video.mix_name}: ${video.playcount}`);
|
||||||
|
console.log(`封面: ${video.cover_image_url}`);
|
||||||
|
console.log(`链接: ${video.video_url}`);
|
||||||
|
console.log(`视频数量: ${video.aweme_ids.length}`);
|
||||||
|
});
|
||||||
|
console.log('分页信息:', res.data.pagination);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
fail: function(err) {
|
|
||||||
console.error('请求失败:', err);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 搜索剧本
|
// 搜索视频
|
||||||
wx.request({
|
wx.request({
|
||||||
url: 'http://你的服务器IP:5000/api/search',
|
url: 'http://localhost:5001/api/search',
|
||||||
method: 'GET',
|
|
||||||
data: {
|
data: {
|
||||||
name: '九尾狐'
|
q: '奶团',
|
||||||
|
page: 1,
|
||||||
|
limit: 5
|
||||||
},
|
},
|
||||||
success: function(res) {
|
success: function(res) {
|
||||||
if (res.data.success) {
|
if (res.data.success) {
|
||||||
const searchResults = res.data.data;
|
const results = res.data.data;
|
||||||
// 显示搜索结果
|
results.forEach(video => {
|
||||||
|
console.log(`找到: ${video.mix_name}`);
|
||||||
|
console.log(`播放量: ${video.playcount}`);
|
||||||
|
console.log(`数值播放量: ${video.play_vv}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取热门榜单
|
||||||
|
wx.request({
|
||||||
|
url: 'http://localhost:5001/api/top',
|
||||||
|
data: {
|
||||||
|
limit: 10
|
||||||
|
},
|
||||||
|
success: function(res) {
|
||||||
|
if (res.data.success) {
|
||||||
|
console.log('热门榜单:', res.data.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🔄 数据更新机制
|
### uni-app示例
|
||||||
|
|
||||||
1. **自动更新**: 每天24:00自动运行抓取脚本
|
```javascript
|
||||||
2. **实时同步**: 抓取完成后,API立即返回最新数据
|
// 封装API请求
|
||||||
3. **排序规则**: 数据按播放量自动排序,最高播放量排第一
|
const API_BASE = 'http://localhost:5001';
|
||||||
|
|
||||||
## 📊 数据字段说明
|
// 获取视频列表
|
||||||
|
export function getVideoList(page = 1, limit = 20, sort = 'playcount') {
|
||||||
|
return uni.request({
|
||||||
|
url: `${API_BASE}/api/videos`,
|
||||||
|
data: { page, limit, sort }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
| 字段名 | 类型 | 说明 |
|
// 搜索视频
|
||||||
|--------|------|------|
|
export function searchVideos(keyword, page = 1, limit = 10) {
|
||||||
| rank | number | 排名(1为最高) |
|
return uni.request({
|
||||||
| script_name | string | 剧本名称 |
|
url: `${API_BASE}/api/search`,
|
||||||
| playcount | string | 播放量文本(如"2.1亿") |
|
data: { q: keyword, page, limit }
|
||||||
| playcount_number | number | 播放量数值(用于排序) |
|
});
|
||||||
| update_time | string | 更新时间 |
|
}
|
||||||
|
|
||||||
## ⚠️ 注意事项
|
// 获取视频详情
|
||||||
|
export function getVideoDetail(id) {
|
||||||
|
return uni.request({
|
||||||
|
url: `${API_BASE}/api/detail`,
|
||||||
|
data: { id }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
1. **服务器地址**: 请将`localhost`替换为实际的服务器IP地址
|
// 使用示例
|
||||||
2. **端口配置**: 默认端口5000,可在服务器代码中修改
|
getVideoList(1, 10).then(([err, res]) => {
|
||||||
3. **数据更新**: 数据每天更新一次,建议小程序缓存数据
|
if (!err && res.data.success) {
|
||||||
4. **错误处理**: 请在小程序中添加网络错误处理逻辑
|
console.log('视频列表:', res.data.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## 🛠️ 启动API服务器
|
## 🎯 数据字段说明
|
||||||
|
|
||||||
|
### 视频合集字段
|
||||||
|
- `_id`: 合集唯一标识符(MongoDB ObjectId)
|
||||||
|
- `mix_name`: 合集名称
|
||||||
|
- `playcount`: 播放量文本(如"2.1亿")
|
||||||
|
- `play_vv`: 播放量数值
|
||||||
|
- `video_url`: 合集链接
|
||||||
|
- `rank`: 排名
|
||||||
|
- `batch_time`: 批次时间
|
||||||
|
- `aweme_ids`: 视频ID数组
|
||||||
|
- `cover_image_url`: 封面图片URL
|
||||||
|
- `cover_backup_urls`: 备用封面图片URL数组
|
||||||
|
- `request_id`: 请求ID
|
||||||
|
|
||||||
|
### 分页信息字段
|
||||||
|
- `page`: 当前页码
|
||||||
|
- `limit`: 每页数量
|
||||||
|
- `total`: 总记录数
|
||||||
|
- `pages`: 总页数
|
||||||
|
- `has_next`: 是否有下一页
|
||||||
|
- `has_prev`: 是否有上一页
|
||||||
|
|
||||||
|
## 🔧 技术特性
|
||||||
|
|
||||||
|
### 1. 小程序优化
|
||||||
|
- **轻量级响应**: 精简数据结构,减少传输量
|
||||||
|
- **分页支持**: 避免一次性加载大量数据
|
||||||
|
- **搜索功能**: 支持关键词模糊搜索
|
||||||
|
- **错误处理**: 统一的错误响应格式
|
||||||
|
|
||||||
|
### 2. 性能优化
|
||||||
|
- **数据缓存**: MongoDB查询优化
|
||||||
|
- **分页限制**: 防止过大的数据请求
|
||||||
|
- **连接池**: 数据库连接复用
|
||||||
|
- **日志记录**: 完整的请求日志
|
||||||
|
|
||||||
|
### 3. 安全特性
|
||||||
|
- **参数验证**: 输入参数安全检查
|
||||||
|
- **CORS支持**: 跨域请求支持
|
||||||
|
- **错误隐藏**: 不暴露内部错误信息
|
||||||
|
|
||||||
|
## 📊 测试结果
|
||||||
|
|
||||||
|
最新测试结果(100%通过率):
|
||||||
|
- ✅ API首页: 正常
|
||||||
|
- ✅ 健康检查: 数据库连接正常,35条记录
|
||||||
|
- ✅ 视频列表: 分页功能正常
|
||||||
|
- ✅ 热门榜单: 排序功能正常
|
||||||
|
- ✅ 搜索功能: 关键词搜索正常
|
||||||
|
- ✅ 视频详情: 详情获取正常
|
||||||
|
- ✅ 统计信息: 数据统计正常
|
||||||
|
|
||||||
|
## 🚀 部署建议
|
||||||
|
|
||||||
|
### 开发环境
|
||||||
```bash
|
```bash
|
||||||
# 安装依赖
|
# 启动API服务器
|
||||||
pip install -r requirements.txt
|
python scripts/miniprogram_api_server.py
|
||||||
|
|
||||||
# 启动服务器
|
# 运行测试
|
||||||
python douyin_api_server.py
|
python scripts/test_miniprogram_api.py
|
||||||
```
|
```
|
||||||
|
|
||||||
服务器启动后会显示:
|
### 生产环境
|
||||||
```
|
```bash
|
||||||
🚀 启动抖音播放量API服务器...
|
# 使用Gunicorn部署
|
||||||
📡 API地址: http://localhost:5000
|
pip install gunicorn
|
||||||
|
gunicorn -w 4 -b 0.0.0.0:5001 scripts.miniprogram_api_server:app
|
||||||
|
|
||||||
|
# 使用Nginx反向代理
|
||||||
|
# 配置SSL证书支持HTTPS
|
||||||
```
|
```
|
||||||
|
|
||||||
## 📞 技术支持
|
## 📝 更新日志
|
||||||
|
|
||||||
|
### v2.0 (2025-10-16)
|
||||||
|
- 🎉 全新的小程序优化API
|
||||||
|
- ✨ 添加分页和搜索功能
|
||||||
|
- 🔧 优化数据结构和响应格式
|
||||||
|
- 📊 增加统计信息接口
|
||||||
|
- 🧪 完整的测试覆盖
|
||||||
|
|
||||||
|
### 与v1.0的主要区别
|
||||||
|
- **更好的分页**: 支持灵活的分页参数
|
||||||
|
- **搜索功能**: 关键词模糊搜索
|
||||||
|
- **详情接口**: 单独的视频详情查看
|
||||||
|
- **统计分析**: 数据统计和分类
|
||||||
|
- **小程序优化**: 专为小程序设计的数据格式
|
||||||
|
|
||||||
|
## 🤝 技术支持
|
||||||
|
|
||||||
如有问题,请检查:
|
如有问题,请检查:
|
||||||
1. MongoDB是否正常运行
|
1. MongoDB服务是否正常运行
|
||||||
2. 服务器端口是否被占用
|
2. API服务器是否启动成功
|
||||||
3. 网络连接是否正常
|
3. 网络连接是否正常
|
||||||
4. 数据是否已更新
|
4. 参数格式是否正确
|
||||||
|
|
||||||
|
测试工具会自动生成详细的测试报告,保存在 `api_test_report.json` 文件中。
|
||||||
@ -52,15 +52,12 @@ pip install -r requirements.txt
|
|||||||
- 确保已安装Chrome浏览器
|
- 确保已安装Chrome浏览器
|
||||||
- 系统会自动检测并使用合适的ChromeDriver
|
- 系统会自动检测并使用合适的ChromeDriver
|
||||||
|
|
||||||
### 2. Chrome配置文件设置
|
### 2. Chrome配置文件
|
||||||
|
|
||||||
**重要**: Chrome配置文件包含登录信息和缓存,需要手动设置。详细步骤请参考:[CHROME_PROFILE_SETUP.md](../CHROME_PROFILE_SETUP.md)
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 首次运行需要手动登录
|
# 首次运行需要手动登录
|
||||||
python scripts/douyin_selenium_cdp_play_vv.py
|
python scripts/douyin_selenium_cdp_play_vv.py
|
||||||
|
自动创建
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. ChromeDriver说明
|
### 3. ChromeDriver说明
|
||||||
|
|
||||||
**ChromeDriver已包含在仓库中** (`drivers/chromedriver.exe`),无需额外下载。系统会自动检测并使用该驱动。
|
**ChromeDriver已包含在仓库中** (`drivers/chromedriver.exe`),无需额外下载。系统会自动检测并使用该驱动。
|
||||||
|
|||||||
190
docs/定时任务配置说明.md
190
docs/定时任务配置说明.md
@ -1,190 +0,0 @@
|
|||||||
# 抖音播放量自动更新定时任务配置说明
|
|
||||||
|
|
||||||
## 概述
|
|
||||||
本文档详细说明如何配置Windows任务计划程序,实现每天晚上24:00(凌晨0点)自动运行抖音播放量抓取脚本。
|
|
||||||
|
|
||||||
## 前置条件
|
|
||||||
|
|
||||||
### 1. 确保MongoDB服务已安装并配置为自动启动
|
|
||||||
- 下载并安装MongoDB Community Server
|
|
||||||
- 配置MongoDB服务为自动启动:
|
|
||||||
```cmd
|
|
||||||
sc config MongoDB start= auto
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 确保Python环境正确
|
|
||||||
- Python 3.7+ 已安装
|
|
||||||
- 所需依赖包已安装:
|
|
||||||
```cmd
|
|
||||||
pip install selenium pymongo webdriver-manager
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. 浏览器登录状态保持
|
|
||||||
- **重要**:首次运行前,需要手动运行脚本并登录抖音账号
|
|
||||||
- 登录后,浏览器会保存登录状态到 `chrome_profile` 目录
|
|
||||||
- 自动模式将使用已保存的登录状态
|
|
||||||
|
|
||||||
## 配置步骤
|
|
||||||
|
|
||||||
### 步骤1:创建日志目录
|
|
||||||
在脚本目录下创建 `logs` 文件夹:
|
|
||||||
```cmd
|
|
||||||
mkdir c:\Users\EDY\Desktop\test\logs
|
|
||||||
```
|
|
||||||
|
|
||||||
### 步骤2:测试批处理脚本
|
|
||||||
手动运行批处理脚本测试:
|
|
||||||
```cmd
|
|
||||||
cd c:\Users\EDY\Desktop\test
|
|
||||||
auto_update_douyin.bat
|
|
||||||
```
|
|
||||||
|
|
||||||
### 步骤3:打开任务计划程序
|
|
||||||
1. 按 `Win + R`,输入 `taskschd.msc`,回车
|
|
||||||
2. 或者在开始菜单搜索"任务计划程序"
|
|
||||||
|
|
||||||
### 步骤4:创建基本任务
|
|
||||||
1. 在右侧操作面板点击"创建基本任务"
|
|
||||||
2. 输入任务名称:`抖音播放量自动更新`
|
|
||||||
3. 输入描述:`每天凌晨0点自动抓取抖音收藏合集播放量数据`
|
|
||||||
|
|
||||||
### 步骤5:设置触发器
|
|
||||||
1. 选择"每天"
|
|
||||||
2. 设置开始时间:`22:00:00`(晚上10点)
|
|
||||||
3. 设置开始日期:选择明天的日期
|
|
||||||
4. 重复间隔:`每 1 天`
|
|
||||||
|
|
||||||
### 步骤6:设置操作
|
|
||||||
1. 选择"启动程序"
|
|
||||||
2. 程序或脚本:`c:\Users\EDY\Desktop\test\auto_update_douyin.bat`
|
|
||||||
3. 添加参数:`--silent`
|
|
||||||
4. 起始于:`c:\Users\EDY\Desktop\test`
|
|
||||||
|
|
||||||
### 步骤7:高级设置
|
|
||||||
1. 勾选"如果任务失败,重新启动"
|
|
||||||
2. 设置重新启动间隔:`5分钟`
|
|
||||||
3. 设置重新启动次数:`3次`
|
|
||||||
4. 勾选"如果请求后任务还在运行,强行将其停止"
|
|
||||||
5. 设置停止任务时间:`2小时`
|
|
||||||
|
|
||||||
### 步骤8:条件设置
|
|
||||||
1. 取消勾选"只有在计算机使用交流电源时才启动此任务"
|
|
||||||
2. 勾选"唤醒计算机运行此任务"
|
|
||||||
3. 勾选"如果任务运行时间超过以下时间,则停止任务:2小时"
|
|
||||||
|
|
||||||
## 文件结构
|
|
||||||
```
|
|
||||||
c:\Users\EDY\Desktop\test\
|
|
||||||
├── douyin_playcount_scraper.py # 主抓取脚本
|
|
||||||
├── auto_update_douyin.bat # 批处理启动脚本
|
|
||||||
├── query_mongodb_data.py # 数据查询脚本
|
|
||||||
├── chrome_profile\ # 浏览器配置文件目录
|
|
||||||
├── logs\ # 日志文件目录
|
|
||||||
│ ├── auto_update_20241215.log # 每日日志文件
|
|
||||||
│ └── ...
|
|
||||||
├── douyin_collection_data.json # JSON数据文件
|
|
||||||
├── douyin_collection_playcounts.txt # TXT格式数据文件
|
|
||||||
└── 定时任务配置说明.md # 本说明文档
|
|
||||||
```
|
|
||||||
|
|
||||||
## 日志文件说明
|
|
||||||
|
|
||||||
### 日志位置
|
|
||||||
- 批处理日志:`logs\auto_update_YYYYMMDD.log`
|
|
||||||
- Python程序日志:同一文件,包含详细的执行信息
|
|
||||||
|
|
||||||
### 日志内容
|
|
||||||
- 任务开始和结束时间
|
|
||||||
- MongoDB连接状态
|
|
||||||
- 数据抓取进度
|
|
||||||
- 文件保存结果
|
|
||||||
- 错误信息(如有)
|
|
||||||
|
|
||||||
## 数据存储说明
|
|
||||||
|
|
||||||
### MongoDB数据结构
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"batch_id": "20241215_000000_abc123",
|
|
||||||
"batch_time": "2024-12-15 00:00:00",
|
|
||||||
"name": "剧本名称",
|
|
||||||
"playcount": "1.2万",
|
|
||||||
"playcount_raw": 12000
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 数据特点
|
|
||||||
- 每次运行生成新的批次ID
|
|
||||||
- 最新数据排在前面(按时间倒序)
|
|
||||||
- 历史数据完整保留
|
|
||||||
- 支持按剧本名称搜索历史数据
|
|
||||||
|
|
||||||
## 故障排除
|
|
||||||
|
|
||||||
### 常见问题
|
|
||||||
|
|
||||||
#### 1. MongoDB连接失败
|
|
||||||
**症状**:日志显示"MongoDB连接失败"
|
|
||||||
**解决方案**:
|
|
||||||
```cmd
|
|
||||||
# 检查MongoDB服务状态
|
|
||||||
sc query MongoDB
|
|
||||||
|
|
||||||
# 启动MongoDB服务
|
|
||||||
net start MongoDB
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 2. 浏览器登录失效
|
|
||||||
**症状**:抓取失败,提示需要登录
|
|
||||||
**解决方案**:
|
|
||||||
1. 手动运行脚本:`python douyin_playcount_scraper.py`
|
|
||||||
2. 重新登录抖音账号
|
|
||||||
3. 登录状态会自动保存到 `chrome_profile` 目录
|
|
||||||
|
|
||||||
#### 3. Python环境问题
|
|
||||||
**症状**:批处理脚本报错"Python未安装"
|
|
||||||
**解决方案**:
|
|
||||||
1. 确认Python已安装:`python --version`
|
|
||||||
2. 确认Python在系统PATH中
|
|
||||||
3. 重新安装依赖:`pip install -r requirements.txt`
|
|
||||||
|
|
||||||
#### 4. 权限问题
|
|
||||||
**症状**:任务计划程序无法执行
|
|
||||||
**解决方案**:
|
|
||||||
1. 以管理员身份运行任务计划程序
|
|
||||||
2. 设置任务以最高权限运行
|
|
||||||
3. 确保用户账户有足够权限
|
|
||||||
|
|
||||||
### 监控和维护
|
|
||||||
|
|
||||||
#### 查看任务执行历史
|
|
||||||
1. 打开任务计划程序
|
|
||||||
2. 找到"抖音播放量自动更新"任务
|
|
||||||
3. 查看"历史记录"选项卡
|
|
||||||
|
|
||||||
#### 查看数据抓取结果
|
|
||||||
运行查询脚本:
|
|
||||||
```cmd
|
|
||||||
python query_mongodb_data.py
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 手动测试
|
|
||||||
定期手动运行测试:
|
|
||||||
```cmd
|
|
||||||
python douyin_playcount_scraper.py --auto-mode
|
|
||||||
```
|
|
||||||
|
|
||||||
## 注意事项
|
|
||||||
|
|
||||||
1. **网络连接**:确保计算机在凌晨0点时有稳定的网络连接
|
|
||||||
2. **电源管理**:建议设置计算机不要在夜间自动休眠
|
|
||||||
3. **防火墙**:确保防火墙不会阻止浏览器和MongoDB的网络访问
|
|
||||||
4. **磁盘空间**:定期清理旧的日志文件,避免占用过多磁盘空间
|
|
||||||
5. **数据备份**:建议定期备份MongoDB数据库
|
|
||||||
|
|
||||||
## 联系支持
|
|
||||||
如遇到问题,请检查:
|
|
||||||
1. 日志文件中的错误信息
|
|
||||||
2. 任务计划程序的执行历史
|
|
||||||
3. MongoDB服务状态
|
|
||||||
4. 网络连接状态
|
|
||||||
33
docs/需求.md
33
docs/需求.md
@ -1,33 +0,0 @@
|
|||||||
现在这是我的项目概览:
|
|
||||||
项目概览
|
|
||||||
|
|
||||||
- 目标:抓取抖音“合集”和“单个视频”的数据,用于分析。
|
|
||||||
- 技术: selenium + webdriver-manager ,少量 requests ;支持无头模式与手动登录。
|
|
||||||
- 能力:从页面源码 JSON、DOM 选择器等多源提取数据,含反爬规避与调试截图。
|
|
||||||
脚本与输出
|
|
||||||
|
|
||||||
- douyin_scraper.py :抓取合集数据(标题、播放/点赞统计、视频列表);输出 douyin_collection_data.json 。
|
|
||||||
- douyin_scraper_enhanced.py :合集增强版(手动登录、页面状态分析、截图);输出 douyin_collection_data_enhanced.json 。
|
|
||||||
- douyin_video_scraper.py :抓取单视频互动数据(点赞/评论/分享/收藏/播放等)、基本信息与评论采样;输出 douyin_video_data.json ,保存页面截图。
|
|
||||||
运行与依赖
|
|
||||||
|
|
||||||
- 依赖: requirements.txt ( selenium 、 requests 、 webdriver-manager )。
|
|
||||||
- 运行示例: python3 douyin_scraper.py 、交互式增强版/视频版可选择手动登录。
|
|
||||||
注意事项
|
|
||||||
|
|
||||||
- 合规与频控:遵守平台条款与法律,控制抓取频率。
|
|
||||||
- 结构变更:抖音页面结构可能更新,需调整选择器/解析逻辑。
|
|
||||||
- 环境匹配:确保本机 Chrome 与 ChromeDriver 版本兼容。
|
|
||||||
|
|
||||||
需求:
|
|
||||||
根据链接https://www.douyin.com/video/7556193043586600201
|
|
||||||
后面的7556193043586600201是可以替换的,获取到所有的短剧集数视频列表
|
|
||||||
7556193043586600201这个就是集数,每一集的这个都不一样
|
|
||||||
进行爬取短剧的点赞数,评论数,收藏数,全部评论内容
|
|
||||||
|
|
||||||
总体来说就是输入视频的链接也就是这个https://www.douyin.com/video/7556193043586600201,然后就可以自动的获取到该系列所有的视频列表,有了列表之后只需要遍历列表,对每个视频进行单独的爬取,之后就可以获取到该视频的点赞数、收藏数、评论数、评论内容了,获取的视频列表一定要保存起来
|
|
||||||
|
|
||||||
但是现在有一个简单的要求,就是可以输入一个视频的链接,然后只对这一集来进行爬取点赞数、收藏数、评论数、评论内容
|
|
||||||
|
|
||||||
流程:
|
|
||||||
输入视频链接->自动识别短剧集数列表->通过列表抓取所有集数短剧视频->获取该系列每个视频的点赞数、收藏数、评论数、评论内容->打印出来即可
|
|
||||||
@ -22,13 +22,17 @@ from datetime import datetime
|
|||||||
def setup_logging():
|
def setup_logging():
|
||||||
"""设置日志配置"""
|
"""设置日志配置"""
|
||||||
# 确保logs目录存在
|
# 确保logs目录存在
|
||||||
os.makedirs('../logs', exist_ok=True)
|
import os
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
project_root = os.path.dirname(script_dir)
|
||||||
|
logs_dir = os.path.join(project_root, 'logs')
|
||||||
|
os.makedirs(logs_dir, exist_ok=True)
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler('../logs/scheduler.log', encoding='utf-8'),
|
logging.FileHandler(os.path.join(logs_dir, 'scheduler.log'), encoding='utf-8'),
|
||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
@ -35,7 +35,22 @@ from pymongo import MongoClient
|
|||||||
from pymongo.errors import ConnectionFailure
|
from pymongo.errors import ConnectionFailure
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format='[%(levelname)s] %(message)s')
|
# 配置日志
|
||||||
|
# 确保logs目录存在
|
||||||
|
import os
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
project_root = os.path.dirname(script_dir)
|
||||||
|
logs_dir = os.path.join(project_root, 'logs')
|
||||||
|
os.makedirs(logs_dir, exist_ok=True)
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format='[%(levelname)s] %(message)s',
|
||||||
|
handlers=[
|
||||||
|
logging.FileHandler(os.path.join(logs_dir, 'douyin_scraper.log'), encoding='utf-8'),
|
||||||
|
logging.StreamHandler()
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class DouyinPlayVVScraper:
|
class DouyinPlayVVScraper:
|
||||||
|
|||||||
@ -14,11 +14,18 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# 配置日志
|
# 配置日志
|
||||||
|
# 确保logs目录存在
|
||||||
|
import os
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
project_root = os.path.dirname(script_dir)
|
||||||
|
logs_dir = os.path.join(project_root, 'logs')
|
||||||
|
os.makedirs(logs_dir, exist_ok=True)
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO,
|
level=logging.INFO,
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(levelname)s - %(message)s',
|
||||||
handlers=[
|
handlers=[
|
||||||
logging.FileHandler('miniprogram_api.log', encoding='utf-8'),
|
logging.FileHandler(os.path.join(logs_dir, 'miniprogram_api.log'), encoding='utf-8'),
|
||||||
logging.StreamHandler()
|
logging.StreamHandler()
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user