有没有办法编写 python 代码来从 github 下载 zip 文件?
Is there a way to write python code to download zip file from github?
我正在尝试自动从 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 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()
我正在尝试自动从 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 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()