Download file from web in Python 3

前端 未结 9 698
星月不相逢
星月不相逢 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:17

    I hope I understood the question right, which is: how to download a file from a server when the URL is stored in a string type?

    I download files and save it locally using the below code:

    import requests
    
    url = 'https://www.python.org/static/img/python-logo.png'
    fileName = 'D:\Python\dwnldPythonLogo.png'
    req = requests.get(url)
    file = open(fileName, 'wb')
    for chunk in req.iter_content(100000):
        file.write(chunk)
    file.close()
    

提交回复
热议问题