import urllib2 from settings import COOKIES opener = urllib2.build_opener() cookies = ";".join("%s=%s" % (k, v) for k, v in COOKIES.items()) opener.addheaders.append(('Cookie', cookies)) req = opener.open(link) meta = req.info() file_size = int(meta.getheaders("Content-Length")[0]) content_type = meta.getheaders('Content-Type')[0].split(';')[0] print file_size, content_type open(file_name, 'wb').write(req.read())
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/8365.html