我想从github存储库获取所有文件(和子目录以及其中的文件)。我不想使用git包,因为这需要我安装git (在windows上,所以这不是自动的事情)。
愿意使用urllib或其他工具。我用的是python 2。
我可以从这里获得一个文件< How to download and write a file from Github using Requests >:
filename = getcwd() + '\\somefile.txt'
url = 'https://raw.github.com/kennethreitz/requests/master/README.rst'
r=requests.get(url)
with open(filename,'w+') as f:
f.write(r.content)如何复制整个repo?
发布于 2018-07-26 07:44:28
您可以通过向https://github.com/user/repo/archive/branch.zip url发出请求,以.zip文件的形式下载整个github存储库。其中branch是您想要下载的分支的名称(通常是主分支)。
示例:
import os
filename = os.path.join(os.getcwd(), 'repo.zip')
url = 'https://github.com/requests/requests/archive/master.zip'
r = requests.get(url)
with open(filename, 'wb') as f:
f.write(r.content)您还应该以二进制模式打开该文件,以防万一(使用wb),因为它正在保存.zip文件。
https://stackoverflow.com/questions/51529060
复制相似问题