有没有办法编写python代码从github下载zip文件?
我正在尝试从github自动下载数据。假设github中的文件位于zip文件夹中。有没有办法编写python代码来下载整个zip文件夹 我使用了request方法,但它不起作用。代码可以正常运行,但文件明显小于原始文件,我无法通过双击打开它,错误消息为“文件无效”有没有办法编写python代码从github下载zip文件?,python,github-api,Python,Github Api,我正在尝试从github自动下载数据。假设github中的文件位于zip文件夹中。有没有办法编写python代码来下载整个zip文件夹 我使用了request方法,但它不起作用。代码可以正常运行,但文件明显小于原始文件,我无法通过双击打开它,错误消息为“文件无效” import requests URL = 'https://github.com/XYZ/file.zip' r = requests.get(url) # open method to open a file on your s
import requests
URL = 'https://github.com/XYZ/file.zip'
r = requests.get(url)
# open method to open a file on your system and write the contents
with open("file.zip", "wb") as code:
code.write(r.content)
解决方法之一是在Python中运行shell命令克隆文件,然后使用Python代码在本地解压
from subprocess import check_output
cmd = '!git clone https://github.com/XYI/file.git C:/Users/UserName/Desktop/test'
check_output(cmd, shell=True).decode()
瞧,我在这件事上支持@Craicerjack。在证明绝对没有办法之前,我想说:当你陷入困境时,试着向我汇报。请更具体一些。您是否正在以zip文件的形式下载GitHub项目?GitHub项目是否有标记/发布/可下载链接?是否有一个版本为git repo的zip文件?答案因您遇到的场景类型而异