Download file from web in Python 3

前端 未结 9 668
星月不相逢
星月不相逢 2020-11-22 16:43

I am creating a program that will download a .jar (java) file from a web server, by reading the URL that is specified in the .jad file of the same game/application. I\'m usi

9条回答
  •  耶瑟儿~
    2020-11-22 17:28

    I use requests package whenever I want something related to HTTP requests because its API is very easy to start with:

    first, install requests

    $ pip install requests
    

    then the code:

    from requests import get  # to make GET request
    
    
    def download(url, file_name):
        # open in binary mode
        with open(file_name, "wb") as file:
            # get request
            response = get(url)
            # write to file
            file.write(response.content)
    

提交回复
热议问题