SoFunction
Updated on 2024-12-17

python implementation of downloading files from the network and get the size and type of the file

This article example describes the python implementation of downloading files from the network and get the file size and type. Shared for your reference. Specific implementation methods are as follows:

import urllib2
from settings import COOKIES
opener = urllib2.build_opener()
cookies = ";".join("%s=%s" % (k, v) for k, v in ())
(('Cookie', cookies))
req = (link)
meta = ()
file_size = int(("Content-Length")[0])
content_type = ('Content-Type')[0].split(';')[0]
print file_size, content_type
open(file_name, 'wb').write(())

I hope that what I have said in this article will help you in your Python programming.