python requests header

url = "https://www.dropbox.com/sh/5shvr16c0xtv0lr/AAD8CcuyPqDTf0xbiitBZkVta?dl=1"
ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'
header = {"User-Agent": ua}
r = requests.get(url, headers=header)

for key in r.headers:
    print("{} - {}".format(str(key), r.headers[key]))

Server - nginx
Date - Wed, 15 May 2019 01:51:12 GMT
Content-Type - application/zip
Transfer-Encoding - chunked
Connection - keep-alive
x-robots-tag - noindex, nofollow, noimageindex
content-disposition - attachment; filename=iPhone.zip
set-cookie - uc_session=XKqn5nlvHUy7RRSKHhWEXd8Uh4704oGu6UWtuuXgWYPjXzQ92Lymm148KGoPZi7H; Domain=dropboxusercontent.com; httponly; Path=/; secure
content-security-policy - sandbox allow-forms allow-scripts allow-top-navigation allow-popups ; report-uri https://www.dropbox.com/csp_log?policy_name=blockserver-usercontent, form-action 'none' ; report-uri https://www.dropbox.com/csp_log?policy_name=blockserver-noscript ; script-src 'none'
x-dropbox-request-id - 74b33acbba1edf11a9c4b7ed075f1933
pragma - public
cache-control - max-age=0
referrer-policy - no-referrer
Vary - Origin
X-Server-Response-Time - 263
Strict-Transport-Security - max-age=15552000; includeSubDomains

 

import time

headers = dict()
headers["Content-Type"] = "text/html; charset=utf-8"
headers["Content-Type"] = "application/zip"
headers["content-disposition"] = "attachment; filename=iPhone.zip"


file_name = time.strftime("%y%m%d%H%M%S", time.localtime())
if "content-disposition" in headers:
    for item in headers["content-disposition"].split("; "):
        if item.split("=")[0] == "filename":
            file_name = item.split("=")[1]
print("file_name={}".format(file_name))

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章