时间:2021-07-01 10:21:17 帮助过:30人阅读
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())
希望本文所述对大家的Python程序设计有所帮助。