Add knowledge base: B站视频《在2000多米高空 建座"会飞的"发电站》
- 新增 knowledge-base/ 目录 - 保存央视新闻视频:在2000多米高空 建座"会飞的"发电站 - 完善 obsidian-kb skill:添加知乎 Playwright 提取器 - 更新依赖和文档
This commit is contained in:
@@ -192,7 +192,11 @@ sources:
|
||||
api_key: '' # YouTube API Key
|
||||
zhihu:
|
||||
enabled: false
|
||||
use_playwright: true # 使用 Playwright 绕过检测(推荐)
|
||||
cookie: '' # 知乎 Cookie (可选)
|
||||
cookie_file: '' # Cookie 文件路径 (可选)
|
||||
timeout: 30 # 超时时间(秒)
|
||||
max_retries: 2 # 最大重试次数
|
||||
|
||||
# Bilibili 提取器配置
|
||||
bilibili_extraction:
|
||||
@@ -272,6 +276,57 @@ else:
|
||||
content["subtitle_text"] = subtitle_text
|
||||
```
|
||||
|
||||
### ZhihuPlaywrightExtractor 类
|
||||
|
||||
ZhihuPlaywrightExtractor 提供了知乎内容的完整提取功能:
|
||||
|
||||
**主要方法:**
|
||||
- `extract(url)` - 提取知乎内容(支持回答、文章、问题)
|
||||
- `identify_url_type(url)` - 识别 URL 类型
|
||||
- `extract_id(url)` - 提取内容 ID
|
||||
|
||||
**特性:**
|
||||
- 使用 Playwright 绕过知乎反爬虫保护
|
||||
- 支持完整 Markdown 格式(代码块、表格、引用等)
|
||||
- 提取元数据:标题、作者、发布时间、点赞数
|
||||
- 智能降级机制(Playwright 失败 → HTTP)
|
||||
- 每次提取独立启动浏览器,内存占用低
|
||||
|
||||
**降级逻辑:**
|
||||
|
||||
当 Playwright 提取失败时:
|
||||
|
||||
1. **ImportError** - Playwright 未安装 → 使用 HTTP 方案
|
||||
2. **TimeoutError** - 网络超时 → 重试后降级
|
||||
3. **403 Forbidden** - 触发反爬虫 → 降级到 HTTP
|
||||
4. **RuntimeError** - 浏览器崩溃 → 降级到 HTTP
|
||||
|
||||
```python
|
||||
from sources.zhihu_playwright_extractor import ZhihuPlaywrightExtractor
|
||||
|
||||
extractor = ZhihuPlaywrightExtractor()
|
||||
data = extractor.extract("https://www.zhihu.com/question/266309957/answer/2003427891925509507")
|
||||
|
||||
print(f"Title: {data['title']}")
|
||||
print(f"Author: {data['author']}")
|
||||
print(f"Content (Markdown): {data['content_markdown']}")
|
||||
```
|
||||
|
||||
**返回数据结构:**
|
||||
```python
|
||||
{
|
||||
'type': 'answer' | 'article' | 'question',
|
||||
'title': str,
|
||||
'author': str,
|
||||
'content': str, # HTML 格式
|
||||
'content_markdown': str, # Markdown 格式
|
||||
'publish_time': str,
|
||||
'vote_up': int,
|
||||
'url': str,
|
||||
'content_id': str
|
||||
}
|
||||
```
|
||||
|
||||
### 使用提取器
|
||||
|
||||
**直接使用提取器:**
|
||||
|
||||
Reference in New Issue
Block a user