我想从github repo获取所有文件(以及子目录和其中的文件)。 我不想使用git包,因为这要求我安装git(在windows上,所以这不是自动的事情)。在
愿意使用urllib或其他东西代替。我在python2上。在
我可以从这里<;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)
如何复制整个回购?在
通过向
https://github.com/user/repo/archive/branch.zip
url发出请求,可以将整个github repo作为.zip文件下载。其中branch
是要下载的分支的名称(通常是master)。在示例:
您还应该以二进制模式打开文件以防万一(使用wb),因为它保存的是一个.zip文件。在
相关问题 更多 >
编程相关推荐