一个高效的GitHub Issues爬虫,支持多进程并发爬取和失败自动重试机制。
- ✅ 多进程并发爬取,提高爬取效率
- ✅ 失败自动重试机制,支持指数退避策略
- ✅ 完整提取Issues的所有信息,包括:
- 基本信息(id、title、url等)
- 创建、更新、关闭时间
- 完整内容(原始Markdown和纯文本)
- Labels标签
- Reactions反应数据
- 所有评论及评论者信息
- Pull Request相关信息
- ✅ 数据保存为JSON格式,便于后续处理
- ✅ 详细的日志记录,方便调试和监控
pip install -r requirements.txt可以通过以下方式提供GitHub Token:
- 在代码中直接传入token参数
- 创建
.env文件(复制.env.example并修改)
测试脚本可以快速验证爬虫功能,默认爬取10个issues:
python test_crawler.py --token ghp_your_token_here可以通过修改github_issues_crawler.py中的主函数部分来执行完整爬取:
if __name__ == '__main__':
crawler = GitHubIssuesCrawler(max_workers=4)
# 爬取所有issues
crawler.crawl(token='ghp_your_token_here')
# 或者限制数量
# crawler.crawl(token='ghp_your_token_here', limit=100)测试脚本支持以下命令行参数:
--token:GitHub API Token(必需)--repo-owner:仓库所有者,默认'tensorflow'--repo-name:仓库名称,默认'tensorflow'--limit:爬取的issues数量限制,默认10--output:输出JSON文件路径,默认'test_issues.json'--workers:进程池工作进程数,默认4
- GitHub API有速率限制,使用token可以提高限制
- 对于大型仓库,完整爬取可能需要较长时间
- 建议使用多个token轮换以进一步提高爬取效率
- 请合理设置并发数,避免触发GitHub的滥用检测
可以在GitHubIssuesCrawler类初始化时调整以下参数:
max_workers:进程池大小,默认4max_retries:失败重试次数,默认5backoff_factor:退避因子,默认2
输出的JSON文件包含以下字段:
{
"id": 123456789,
"title": "Issue标题",
"html_url": "https://github.com/owner/repo/issues/123",
"url": "https://api.github.com/repos/owner/repo/issues/123",
"state": "open",
"created_at": "2023-01-01T12:00:00Z",
"updated_at": "2023-01-02T12:00:00Z",
"closed_at": null,
"state_reason": null,
"body": "## Markdown内容\n这是issue的内容",
"body_text": "Markdown内容 这是issue的内容",
"labels": [{"id": 123, "name": "bug", "color": "ff0000"}],
"reactions": {
"+1": 5,
"-1": 0,
"laugh": 1,
"confused": 0,
"heart": 3,
"hooray": 2,
"rocket": 0,
"eyes": 0
},
"comments": [
{
"id": 987654321,
"body": "评论内容",
"body_text": "评论内容",
"created_at": "2023-01-01T13:00:00Z",
"updated_at": "2023-01-01T13:00:00Z",
"html_url": "https://github.com/owner/repo/issues/123#issuecomment-987654321",
"user": {"login": "username", "id": 123456}
}
],
"pull_request": null
}