Python搜集Github中项目作者信息
2018-03-27 23:14
309 查看
我们将继续学习可视化部分的内容,我们将请求网站信息,并对这些信息进行可视化操作
很多API都要求注册获得API秘钥后才能执行API调用,但是Github没有这样的要求 https://api/github.com/将请求发送到GitHub网站中相应API调用的部分,search/repositories让API搜索 Github上的所有仓库 后面是传递的一个实参 q表示查询,通过language:python指出只想获取主要语言为Python的仓库信息
&sort=stars 指定将项目按其获得的星级进行排序
下面是代码部分:import requests
import sys
url = 'https://api.github.com/search/repositories?q=language:python&sort=starts'
r = requests.get(url)
print("Status Code: ", r.status_code)
# 将API响应存储到一个变量中
response_dict = r.json()
#print(response_dict.keys())
print("Toal repositories:", response_dict['total_count'])
# 查找有关仓库的信息
repo_dicts = response_dict['items']
print("Repositories returned:", len(repo_dicts))
# 打印出所有仓库的项目的一些信息
print("\nSelected information about first repository:")
def getRepositoryInfomation():
# 作者名
print('\nName:', repo_dict['name'])
# 登录名
print('Owner:', repo_dict['owner']['login'])
# 星星个数
print('Stars:', repo_dict['stargazers_count'])
# 仓库的url
print('Repository:', repo_dict['html_url'])
# 创建时间
print('Created:', repo_dict['created_at'])
# 更新时间
print('Updated:', repo_dict['updated_at'])
# 可能会出现这种情况,"description": null这样会返回一个NoneType异常
if type(repo_dict['description']):
print('Description: ', 'null')
else:
# 项目描述
print('Description:', repo_dict['description'])
for repo_dict in repo_dicts:
getRepositoryInfomation()
'''
Status Code: 200
Toal repositories: 2484834
Repositories returned: 30
Selected information about first repository:
Name: awesome-python
Owner: vinta
Stars: 47594
Repository: https://github.com/vinta/awesome-python Created: 2014-06-27T21:00:06Z
Updated: 2018-03-27T14:45:05Z
Description: null
Name: youtube-dl
Owner: rg3
Stars: 35318
Repository: https://github.com/rg3/youtube-dl Created: 2010-10-31T14:35:07Z
Updated: 2018-03-27T15:03:11Z
Description: null
Name: public-apis
Owner: toddmotto
Stars: 34801
Repository: https://github.com/toddmotto/public-apis Created: 2016-03-20T23:49:42Z
Updated: 2018-03-27T14:34:05Z
Description: null
Name: httpie
Owner: jakubroztocil
Stars: 34626
Repository: https://github.com/jakubroztocil/httpie Created: 2012-02-25T12:39:13Z
Updated: 2018-03-27T14:15:34Z
Description: null
snip.....
'''你可以访问点击打开链接 请求API速率有一定的要求,所以一些爬虫就会通过很多个代理Ip进行爬取信息,这里我们可以访问这个链接查看自己的速率限制
下一节我们将使用Pygal可视化这些数据
很多API都要求注册获得API秘钥后才能执行API调用,但是Github没有这样的要求 https://api/github.com/将请求发送到GitHub网站中相应API调用的部分,search/repositories让API搜索 Github上的所有仓库 后面是传递的一个实参 q表示查询,通过language:python指出只想获取主要语言为Python的仓库信息
&sort=stars 指定将项目按其获得的星级进行排序
下面是代码部分:import requests
import sys
url = 'https://api.github.com/search/repositories?q=language:python&sort=starts'
r = requests.get(url)
print("Status Code: ", r.status_code)
# 将API响应存储到一个变量中
response_dict = r.json()
#print(response_dict.keys())
print("Toal repositories:", response_dict['total_count'])
# 查找有关仓库的信息
repo_dicts = response_dict['items']
print("Repositories returned:", len(repo_dicts))
# 打印出所有仓库的项目的一些信息
print("\nSelected information about first repository:")
def getRepositoryInfomation():
# 作者名
print('\nName:', repo_dict['name'])
# 登录名
print('Owner:', repo_dict['owner']['login'])
# 星星个数
print('Stars:', repo_dict['stargazers_count'])
# 仓库的url
print('Repository:', repo_dict['html_url'])
# 创建时间
print('Created:', repo_dict['created_at'])
# 更新时间
print('Updated:', repo_dict['updated_at'])
# 可能会出现这种情况,"description": null这样会返回一个NoneType异常
if type(repo_dict['description']):
print('Description: ', 'null')
else:
# 项目描述
print('Description:', repo_dict['description'])
for repo_dict in repo_dicts:
getRepositoryInfomation()
'''
Status Code: 200
Toal repositories: 2484834
Repositories returned: 30
Selected information about first repository:
Name: awesome-python
Owner: vinta
Stars: 47594
Repository: https://github.com/vinta/awesome-python Created: 2014-06-27T21:00:06Z
Updated: 2018-03-27T14:45:05Z
Description: null
Name: youtube-dl
Owner: rg3
Stars: 35318
Repository: https://github.com/rg3/youtube-dl Created: 2010-10-31T14:35:07Z
Updated: 2018-03-27T15:03:11Z
Description: null
Name: public-apis
Owner: toddmotto
Stars: 34801
Repository: https://github.com/toddmotto/public-apis Created: 2016-03-20T23:49:42Z
Updated: 2018-03-27T14:34:05Z
Description: null
Name: httpie
Owner: jakubroztocil
Stars: 34626
Repository: https://github.com/jakubroztocil/httpie Created: 2012-02-25T12:39:13Z
Updated: 2018-03-27T14:15:34Z
Description: null
snip.....
'''你可以访问点击打开链接 请求API速率有一定的要求,所以一些爬虫就会通过很多个代理Ip进行爬取信息,这里我们可以访问这个链接查看自己的速率限制
下一节我们将使用Pygal可视化这些数据
相关文章推荐
- 修改 Github commit 的作者信息
- GitHub最著名的20个Python机器学习项目
- 统计Github项目信息
- GitHub最著名的20个Python机器学习项目
- GitHub 上最火的 Python 开源项目
- Python基于Flask框架配置依赖包信息的项目迁移部署小技巧
- Github仓库信息配置以及项目上传总结。
- python项目:获取微信好友信息(一)抓取微信好友数据
- Github社区python项目数据分析
- 盘点•GitHub最著名的20个Python机器学习项目
- Python爬虫使用脚本登录Github并查看信息
- python3小项目——爬取智联招聘信息(二)
- 材料院项目之Python读取配置信息
- 从15000个Python开源项目中精选的Top30,Github平均star为3707,赶紧收藏!
- Python爬虫项目:抓取智联招聘信息
- FaceRank-项目上了 GitHub Python Trending
- 从15000个Python开源项目中精选的Top30,Github平均star为3707,赶紧收藏!
- Python开发【项目】:生产环境下实时统计网站访问日志信息
- python项目:获取微信好友信息(二)csv数据读取与处理
- 如何保持从github上fork过来的项目与作者同步更新