├── .github └── workflows │ └── start.yml ├── README.md ├── img ├── edit.png ├── index.png ├── log.png ├── secret.png └── workflow.png └── main.py /.github/workflows/start.yml: -------------------------------------------------------------------------------- 1 | name: Spider action 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | build: 8 | 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Set up Python 3.8 14 | uses: actions/setup-python@v2 15 | with: 16 | python-version: 3.8 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install requests 21 | - name: Run the script 22 | env: 23 | TOKEN: ${{ secrets.TOKEN }} 24 | run: | 25 | python main.py "$TOKEN" 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 更新 2 | 该版本使用了github的api,相比之前的selenium版本,速度快了十倍左右,而且不需要账号密码及邮箱验证,有效防止了程序的不稳定,新版程序几乎不会无缘无故运行失败(脚本运行过多导致请求超限除外)。 3 | # 介绍 4 | 本项目专门为考试周找不到往年试卷的科大学生定制,它可以在ustc-course相关的230+个仓库上高效爬取需要的课程资料,为了提升速度以及避免使用proxy带来的困难,项目部署在github action上。 5 | # 使用说明 6 | 命令行启动: 7 | ```shell 8 | python main.py 9 | ``` 10 | 其中TOKEN是GitHub的token,可以去设置页面生成。 11 | 可以修改源码第3、4行个性化搜索,设置想搜的学科甚至是外校的仓库(如把搜索关键词由'ustc course'改为'pku course'可搜索北大的学习资料,不过一般都不需要) 12 | workflow启动: 13 | 1、将代码fork到自己的仓库。 14 | 2、点击Actions选项卡,点击`I understand my workflows, go ahead and enable them`。 15 | 3、在Settings/Secrets设置TOKEN。 16 | ![](img/secret.png) 17 | 4、在Action选项卡中启动workflow,运行结果可在日志中看到。 18 | ![](img/workflow.png) 19 | ![](img/log.png) 20 | # 优点 21 | 1、可以辅助提升GPA,助你成为卷王。 22 | 2、比起手动寻找仓库,速度要快几十倍,而且支持并行搜索(同时开启几个workflow即可)。 23 | 3、可以快速得到整个目录树,判断是否是需要的仓库。 24 | # 常见问题 25 | 1、token认证失败(直接体现是repo不存在'item'项),原因可能是不小心把token明文发布到了仓库上,需要重新生成token。 26 | # 附注 27 | 1、脚本也可做其他用途,比如搜其他学校的课程。它的主要功能是在一堆仓库中找出包含某类文件的仓库(比如文件名含有某些字符串)。 28 | 2、熟悉正则表达式的可以改成更强大的正则表达式搜索。 29 | 30 | # Stargazers over time 31 | [![Stargazers over time](https://starchart.cc/Kobe972/ustc-course-spider.svg)](https://starchart.cc/Kobe972/ustc-course-spider) 32 | -------------------------------------------------------------------------------- /img/edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kobe972/ustc-course-spider/ac7057ceeb6ffb1603f3e432aa8f06733e34eafc/img/edit.png -------------------------------------------------------------------------------- /img/index.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kobe972/ustc-course-spider/ac7057ceeb6ffb1603f3e432aa8f06733e34eafc/img/index.png -------------------------------------------------------------------------------- /img/log.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kobe972/ustc-course-spider/ac7057ceeb6ffb1603f3e432aa8f06733e34eafc/img/log.png -------------------------------------------------------------------------------- /img/secret.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kobe972/ustc-course-spider/ac7057ceeb6ffb1603f3e432aa8f06733e34eafc/img/secret.png -------------------------------------------------------------------------------- /img/workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kobe972/ustc-course-spider/ac7057ceeb6ffb1603f3e432aa8f06733e34eafc/img/workflow.png -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import argparse 3 | keys=['编译','compile'] #这里放文件名中要有的关键字 4 | search='ustc course' #这里放搜索关键字 5 | parser = argparse.ArgumentParser(description='Ustc-course Spyder') 6 | parser.add_argument('token', help='token for your github account', type=str) 7 | args = parser.parse_args() 8 | token=args.token 9 | headers={"Authorization":"token "+token} 10 | search=search.replace(' ','+') 11 | url_list=[] 12 | for page in range(1,11): 13 | repo=requests.get("https://api.github.com/search/repositories?q="+search+"&per_page=100&page="+str(page),headers=headers).json() 14 | if(len(repo['items'])==0): 15 | break 16 | for item in repo['items']: 17 | full_name=item['full_name'] 18 | branch=item['default_branch'] 19 | tree_url='https://api.github.com/repos/'+full_name+'/git/trees/'+branch+'?recursive=1' 20 | content=requests.get(tree_url,headers=headers) 21 | if 'tree' not in content.json().keys(): 22 | continue 23 | files=full_name.lower() 24 | for file in content.json()["tree"]: 25 | files+=file['path'].lower() 26 | for key in keys: 27 | if key in files: 28 | url_list.append('https://github.com/'+full_name) 29 | for url in url_list: 30 | print(url) 31 | --------------------------------------------------------------------------------