Python equivalent of a given wget command

前端 未结 10 2222
面向向阳花
面向向阳花 2020-12-02 10:04

I\'m trying to create a Python function that does the same thing as this wget command:

wget -c --read-timeout=5 --tries=0 \"$URL\"

-c

10条回答
  •  佛祖请我去吃肉
    2020-12-02 11:07

    For Windows and Python 3.x, my two cents contribution about renaming the file on download :

    1. Install wget module : pip install wget
    2. Use wget :
    import wget
    wget.download('Url', 'C:\\PathToMyDownloadFolder\\NewFileName.extension')
    

    Truely working command line example :

    python -c "import wget; wget.download(""https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.17.2.tar.xz"", ""C:\\Users\\TestName.TestExtension"")"
    

    Note : 'C:\\PathToMyDownloadFolder\\NewFileName.extension' is not mandatory. By default, the file is not renamed, and the download folder is your local path.

提交回复
热议问题