python使用心得之獲得github代碼庫列表
1.背景
項目需求,要求獲得github的repo的api,以便可以提取repo的數(shù)據(jù)進行分析。研究了一天,終于解決了這個問題,雖然效率還是比較低下。
因為github的那個顯示repo的api,列出了每個repo的詳細信息,而且是json格式的?,F(xiàn)在貌似還沒有找到可以分析多個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,我們可以做一個循環(huán),不斷增大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
相關(guān)文章
布同 Python中文問題解決方法(總結(jié)了多位前人經(jīng)驗,初學(xué)者必看)
首先談?wù)勎沂窃趺从龅絇ython中文輸入問題的。我寫了一個小工具,用來查詢Python的庫函數(shù)。2011-03-03Pandas數(shù)據(jù)類型之category的用法
Pandas中有一種特殊的數(shù)據(jù)類型叫做category.它表示的是一個類別,一般用在統(tǒng)計分類中,比如性別,血型,分類,級別等等.有點像java中的enum,今天給大家詳細講解一下category的用法,需要的朋友可以參考下2021-06-06Python3讀取和寫入excel表格數(shù)據(jù)的示例代碼
這篇文章主要介紹了Python3讀取和寫入excel表格數(shù)據(jù)的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06調(diào)整Jupyter notebook的啟動目錄操作
這篇文章主要介紹了調(diào)整Jupyter notebook的啟動目錄操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04在Django中管理Users和Permissions以及Groups的方法
這篇文章主要介紹了在Django中管理Users和Permissions以及Groups的方法,Django是最具人氣的Python web開發(fā)框架,需要的朋友可以參考下2015-07-07python3 通過 pybind11 使用Eigen加速代碼的步驟詳解
這篇文章主要介紹了python3 通過 pybind11 使用Eigen加速代碼的步驟詳解,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-12-12