简体   繁体   中英

Getting a corupt zip file when download a zip extension using requests with Python

I want to download a test file at [link no longer exists] with a python script.

If you go by yourself to the link, the download will start automaticly.

Although, if I try running this script, I get a corrupt folder.zip file, which is instead an html file:

import os
import requests

URL = "http://kolterdev.epizy.com/dir/VoidShipsUploads/folder.zip"
DIR = os.getcwd()

download = requests.get(URL)

print(download.content)

open(filename, 'wb').write(download.content)

This is the html file I find instead of the zip file:

<html>

<body>
    <script type="text/javascript" src="/aes.js"></script>
    <script>
        function toNumbers(d) {
            var e = [];
            d.replace(/(..)/g, function(d) {
                e.push(parseInt(d, 16))
            });
            return e
        }

        function toHex() {
            for (var d = [], d = 1 == arguments.length && arguments[0].constructor == Array ? arguments[0] : arguments, e = "", f = 0; f < d.length; f++) e += (16 > d[f] ? "0" : "") + d[f].toString(16);
            return e.toLowerCase()
        }
        var a = toNumbers("f655ba9d09a112d4968c63579db590b4"),
            b = toNumbers("98344c2eee86c3994890592585b49f80"),
            c = toNumbers("7a2b1adb5e9b4162d6571ff0b6145a53");
        document.cookie = "__test=" + toHex(slowAES.decrypt(c, 2, a, b)) + "; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";
        location.href = "http://kolterdev.epizy.com/dir/VoidShipsUploads/folder.zip?i=1";
    </script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript>
</body>

</html>

what can I do to get the file?

EDIT: The page with that url does no longer exist.

import urllib.request
...
url = 'http://example.com/'
response = urllib.request.urlopen(url)
data = response.read()      # a `bytes` object
text = data.decode('utf-8') # a `str`; this step can't be used if data is binary

Also, do give this answer a look https://stackoverflow.com/a/7244263/13227971

bash version

import os
url = "http://kolterdev.epizy.com/dir/VoidShipsUploads/folder.zip"
os.system("wget {}".format(url))

you can specify the location using -O

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM