Skip to content

Xuhrrr/ValuesDetector

Repository files navigation

GitHub Issues 爬虫

一个高效的GitHub Issues爬虫,支持多进程并发爬取和失败自动重试机制。

功能特点

  • ✅ 多进程并发爬取,提高爬取效率
  • ✅ 失败自动重试机制,支持指数退避策略
  • ✅ 完整提取Issues的所有信息,包括:
    • 基本信息(id、title、url等)
    • 创建、更新、关闭时间
    • 完整内容(原始Markdown和纯文本)
    • Labels标签
    • Reactions反应数据
    • 所有评论及评论者信息
    • Pull Request相关信息
  • ✅ 数据保存为JSON格式,便于后续处理
  • ✅ 详细的日志记录,方便调试和监控

安装依赖

pip install -r requirements.txt

使用方法

1. 配置GitHub Token

可以通过以下方式提供GitHub Token:

  • 在代码中直接传入token参数
  • 创建.env文件(复制.env.example并修改)

2. 测试爬取功能

测试脚本可以快速验证爬虫功能,默认爬取10个issues:

python test_crawler.py --token ghp_your_token_here

3. 完整爬取

可以通过修改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)

4. 命令行参数说明

测试脚本支持以下命令行参数:

  • --token:GitHub API Token(必需)
  • --repo-owner:仓库所有者,默认'tensorflow'
  • --repo-name:仓库名称,默认'tensorflow'
  • --limit:爬取的issues数量限制,默认10
  • --output:输出JSON文件路径,默认'test_issues.json'
  • --workers:进程池工作进程数,默认4

注意事项

  1. GitHub API有速率限制,使用token可以提高限制
  2. 对于大型仓库,完整爬取可能需要较长时间
  3. 建议使用多个token轮换以进一步提高爬取效率
  4. 请合理设置并发数,避免触发GitHub的滥用检测

配置说明

可以在GitHubIssuesCrawler类初始化时调整以下参数:

  • max_workers:进程池大小,默认4
  • max_retries:失败重试次数,默认5
  • backoff_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
}

About

A method to detect human values in open source artifacts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages