Skip to content

[Python] Use the gdown package to download files from Google Drive

I once wrote the article [Linux] Use "wget" command to download file and [Linux] Use "wget" command to download files from Google Drive, which records how to use the famous wget command in Linux to download Google Drive files that have been given public permissions. Now this article is going to document the package gdown in Python that can be used to download Google Drive files.

Compared with wget, gdown also has its own advantages. For example: gdown can download relatively large-capacity files, wget or curl is easy to report errors when processing large capacity files.


Preparation

First, we put the files we want to share with others on Google Drive.

For example I want to share this beautiful Chinese character with others

And then we need to set the sharing permission, right-click on the file you want to share and select Share.

Then select the permission as Anyone on the internet can find and view.

After setting it up, we can finally let everyone download it. But before using wget, we need to find the download URL.

Enter this link, this link URL is not yet a download URL, just a place where you can view the file.

Click the icon of the download arrow.

The website that pops up, the URL above it is the real download URL. The way to distinguish is very simple, it will end with download.


gdown

Above, the end of copying and pasting. Let's start record usage of gdown, let's look at the code directly:

import gdown

url = "https://drive.google.com/u/1/uc?id=1rt0-DRWWNb18Y2RchhAgx3y2ig2fsB7v&export=download"
output = "test.png"
gdown.download(url, output)



Output:

Downloaded successfully!


Reference

Leave a Reply