Files
nanocode/playwright-hotspots/README.md
T
Ubuntu 32b43f85bd a
2026-07-03 16:58:28 +08:00

110 lines
2.7 KiB
Markdown

# Playwright Hotspots - 中文平台热点抓取
使用 Puppeteer/Playwright 无头浏览器抓取微博、B站、知乎等平台的热点数据。
## 项目结构
```
playwright-hotspots/
├── README.md
├── package.json
├── config/
│ └── browser.js # 浏览器配置
├── src/
│ ├── platforms/
│ │ ├── weibo.js # 微博热搜
│ │ ├── bilibili.js # B站热搜
│ │ ├── zhihu.js # 知乎热榜
│ │ └── xiaohongshu.js # 小红书搜索
│ └── utils/
│ └── helpers.js # 工具函数
├── scripts/
│ ├── get-weibo-hot.js # 获取微博热搜
│ ├── get-bilibili-trending.js # 获取B站热搜
│ └── get-all-hotspots.js # 获取所有平台热点
└── data/ # 输出数据目录
```
## 安装浏览器
### 方式1: 自动安装(推荐,但较慢)
```bash
npx puppeteer browsers install chrome
```
### 方式2: 系统 Chromium
```bash
# Ubuntu/Debian
sudo apt-get install chromium-browser
# 然后在 config/browser.js 中设置
executablePath: '/usr/bin/chromium-browser'
```
### 方式3: 使用已安装的 Chrome
在 `config/browser.js` 中修改 `executablePath` 指向你的 Chrome 路径。
## 使用
```bash
# 获取微博热搜
node scripts/get-weibo-hot.js
# 获取B站热搜
node scripts/get-bilibili-trending.js
# 获取所有平台热点
node scripts/get-all-hotspots.js
```
## 快速开始
### 方式1: 使用全局命令(推荐)
```bash
# 已在 ~/.local/bin/hotspots 创建快捷命令
hotspots weibo # 微博热搜
hotspots bilibili # B站热搜
hotspots zhihu # 知乎热榜
hotspots all # 所有平台
hotspots data # 查看历史数据
```
### 方式2: 在项目目录运行
```bash
cd /home/ubuntu/nanocode/playwright-hotspots
# 检查浏览器环境
node scripts/check-browser.js
# 运行抓取
npm run weibo
npm run bilibili
npm run zhihu
npm run all
```
### 关于系统服务
本项目**不配置为系统服务**,按需手动运行更灵活。
如需定时抓取,可配置 cron 或使用 `hotspots all` 命令。
## 支持平台
| 平台 | 功能 | 状态 | 说明 |
|------|------|------|------|
| 微博 | 热搜榜 | ✅ 可用 | 网页抓取,无需登录 |
| B站 | 热搜榜 | ✅ 可用 | 直接调用 API |
| 知乎 | 热榜 | ✅ 可用 | 直接调用 API |
| 小红书 | 搜索 | ⚠️ 需登录 | 需要 Cookie/登录态 |
## 输出格式
```json
{
"platform": "weibo",
"timestamp": "2026-03-26T17:00:00+08:00",
"items": [
{"rank": 1, "title": "热点标题", "hot": "123万", "url": "..."}
]
}
```