python使用心得之獲得github代碼庫列表
1.背景
項(xiàng)目需求,要求獲得github的repo的api,以便可以提取repo的數(shù)據(jù)進(jìn)行分析。研究了一天,終于解決了這個(gè)問題,雖然效率還是比較低下。
因?yàn)間ithub的那個(gè)顯示repo的api,列出了每個(gè)repo的詳細(xì)信息,而且是json格式的?,F(xiàn)在貌似還沒有找到可以分析多個(gè)json格式數(shù)據(jù)的方法,所以用的是比較蠢得splite加re的方法。如果大家有更好的方法,不發(fā)留言討論!
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,我們可以做一個(gè)循環(huán),不斷增大num的值,就可以無限提取repo。因?yàn)間ithub的api對于流量是有限制的,所以這么做是一個(gè)可行的方法。
效果如下(提取下來的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
相關(guān)文章
借助Paramiko通過Python實(shí)現(xiàn)linux遠(yuǎn)程登陸及sftp的操作
這篇文章主要介紹了借助Paramiko通過Python實(shí)現(xiàn)linux遠(yuǎn)程登陸及sftp,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Python使用asyncio標(biāo)準(zhǔn)庫對異步IO的支持
Python中,所有程序的執(zhí)行都是單線程的,但可同時(shí)執(zhí)行多個(gè)任務(wù),不同的任務(wù)被時(shí)間循環(huán)(Event Loop)控制及調(diào)度,Asyncio是Python并發(fā)編程的一種實(shí)現(xiàn)方式;是Python 3.4版本引入的標(biāo)準(zhǔn)庫,直接內(nèi)置了對異步IO的支持2023-11-11
pytorch GAN生成對抗網(wǎng)絡(luò)實(shí)例
今天小編就為大家分享一篇pytorch GAN生成對抗網(wǎng)絡(luò)實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-01-01
python 實(shí)現(xiàn)手機(jī)自動(dòng)撥打電話的方法(通話壓力測試)
今天小編就為大家分享一篇python 實(shí)現(xiàn)手機(jī)自動(dòng)撥打電話的方法(通話壓力測試),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08

