python使用心得之获得github代码库列表

yipeiwu_com5年前Python基础

1.背景

项目需求,要求获得github的repo的api,以便可以提取repo的数据进行分析。研究了一天,终于解决了这个问题,虽然效率还是比较低下。

因为github的那个显示repo的api,列出了每个repo的详细信息,而且是json格式的。现在貌似还没有找到可以分析多个json格式数据的方法,所以用的是比较蠢得splite加re的方法。如果大家有更好的方法,不发留言讨论!

2.代码

import re
import os

def GetUrl(num):
 str = os.popen("curl -G https://api.github.com/repositories?since=%d"%(num)).read()
 pattern = '"url"'
 pattern1='repos'
 urls=str.split(',\n')  
 for i in urls:
  if pattern in i and pattern1 in i:   
#  text1=i.splite(':')
  text=re.compile('"(.*?)"').findall(i)[1]
  print text
if __name__=='__main__':
 GetUrl(1000)

    其中num的值指的是页面的id,我们可以做一个循环,不断增大num的值,就可以无限提取repo。因为github的api对于流量是有限制的,所以这么做是一个可行的方法。

效果如下(提取下来的repo的api地址):

https://api.github.com/repos/wycats/merb-core

https://api.github.com/repos/rubinius/rubinius

https://api.github.com/repos/mojombo/god

https://api.github.com/repos/vanpelt/jsawesome

https://api.github.com/repos/wycats/jspec

https://api.github.com/repos/defunkt/exception_logger

https://api.github.com/repos/defunkt/ambition

https://api.github.com/repos/technoweenie/restful-authentication

https://api.github.com/repos/technoweenie/attachment_fu

https://api.github.com/repos/topfunky/bong

https://api.github.com/repos/Caged/microsis

https://api.github.com/repos/anotherjesse/s3

https://api.github.com/repos/anotherjesse/taboo

https://api.github.com/repos/anotherjesse/foxtracs

https://api.github.com/repos/anotherjesse/fotomatic

https://api.github.com/repos/mojombo/glowstick

https://api.github.com/repos/defunkt/starling

https://api.github.com/repos/wycats/merb-more

https://api.github.com/repos/macournoyer/thin

https://api.github.com/repos/jamesgolick/resource_controller

https://api.github.com/repos/jamesgolick/markaby

https://api.github.com/repos/jamesgolick/enum_field

https://api.github.com/repos/defunkt/subtlety

https://api.github.com/repos/defunkt/zippy

https://api.github.com/repos/defunkt/cache_fu

https://api.github.com/repos/KirinDave/phosphor

相关文章

pycharm运行scrapy过程图解

pycharm运行scrapy过程图解

这篇文章主要介绍了pycharm运行scrapy过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.打开pycharm, 点击...

Python中实现常量(Const)功能

python语言本身没有提供const,但实际开发中经常会遇到需要使用const的情形,由于语言本身没有这种支出,因此需要使用一些技巧来实现这一功能 定义const类如下 复制代码 代码...

pygame游戏之旅 计算游戏中躲过的障碍数量

pygame游戏之旅 计算游戏中躲过的障碍数量

本文为大家分享了pygame游戏之旅的第8篇,供大家参考,具体内容如下 定义一个计数函数: def things_dodged(count): font = pygame.font...

python、Matlab求定积分的实现

python、Matlab求定积分的实现

python求定积分 计算 from sympy import * x = symbols('x') print(integrate(sin(2*x)/(1+x**2), (x,...

详解用Python处理HTML转义字符的5种方式

写爬虫是一个发送请求,提取数据,清洗数据,存储数据的过程。在这个过程中,不同的数据源返回的数据格式各不相同,有 JSON 格式,有 XML 文档,不过大部分还是 HTML 文档,HTML...