Python爬虫Headers处理脚本-自动加引号

headers = """
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Connection: keep-alive
Cookie:  Hm_lvt_77cbd0be2=1578548910; _lxsdk=AD109456FDFEBDE5C87AD6B; 
Host: maoyan.com
Referer: https://maoyan.com/board/4
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36
"""#放入自己复制的请求头信息
header = ''
for i in headers:
    if i == ':':
        i = "':'"
    if i == '\n':
        i = "',\n'"
    header += i
print(header.replace(' ', '')[2:-2])

输出:

'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;'
'Accept-Language':'zh-CN,zh;q=0.9',
'Connection':'keep-alive',
'Cookie':'Hm_lpvt_703e94591e87be68cc8da0da7cbd0be2=1578552108;mojo-trace-id=3;_lxsdk_s=16f8909a307-33-009-202%7C%7C4',
'Host':'maoyan.com',
'Referer':'https':'//maoyan.com/board/4',
'User-Agent':'Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/79.0.3945.88Safari/537.36',

有问题请联系博主:
微信:hrvrap
qq:2580419087

你可能感兴趣的:(Python爬虫Headers处理脚本-自动加引号)