news-classifier/crawler-module/README.md

95 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 新闻爬虫系统
一个模块化的新闻爬虫系统支持爬取网易新闻和36氪的文章内容。
## 功能特性
- 支持多个新闻源网易娱乐、科技、体育、财经、汽车、政务、健康、军事36氪AI
- 静态页面和动态页面Selenium支持
- 统一的配置管理YAML
- 完善的日志系统
- 数据库连接池优化
- 命令行接口
- 模块化设计,易于扩展
## 快速开始
### 安装依赖
```bash
pip install -r requirements.txt
```
### 配置
编辑 `config/config.yaml` 文件,配置数据库连接和其他参数:
```yaml
database:
host: "localhost"
user: "root"
password: "your_password"
database: "news"
```
### 初始化数据库
执行 `docs/database.md` 中的SQL脚本创建数据表。
### 运行爬虫
```bash
# 列出所有可用爬虫
python -m src.cli.main --list
# 运行单个爬虫
python -m src.cli.main netease:tech
# 运行所有爬虫
python -m src.cli.main --all
# 指定最大文章数
python -m src.cli.main netease:tech --max 5
```
## 项目结构
```
news-crawler/
├── config/ # 配置文件
├── src/ # 源代码
│ ├── base/ # 基类
│ ├── crawlers/ # 爬虫实现
│ ├── parsers/ # 解析器
│ ├── database/ # 数据库模块
│ ├── utils/ # 工具模块
│ └── cli/ # 命令行接口
├── tests/ # 测试
├── docs/ # 文档
└── logs/ # 日志文件
```
## 扩展开发
### 添加新的爬虫
1.`src/crawlers/` 下创建新的爬虫类,继承 `StaticCrawler``DynamicCrawler`
2.`config/config.yaml` 中添加配置
3.`src/cli/main.py` 中注册爬虫
### 添加新的解析器
1.`src/parsers/` 下创建新的解析器类
2. 继承 `BaseParser` 并实现 `parse()` 方法
## 支持的新闻源
| 新闻源 | 分类 | 类型 |
|--------|------|------|
| 网易 | 娱乐、科技、体育、财经、汽车、政务、健康、军事 | 静态/动态 |
| 36氪 | AI | 动态 |
## 许可证
MIT License