import re c = ''' Accept: application/json, text/javascript, */*; q=0.01 Accept-Encoding: gzip, deflate Accept-Language: zh-CN,zh;q=0.9 Connection: keep-alive Content-Length: 242 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Cookie: OUTFOX_SEARCH_USER_ID=-636625617@10.168.1.8; OUTFOX_SEARCH_USER_ID_NCOO=1075352995.079191; Hm_lvt_eaa57ca47dacb4ad4f5a257001a3457c=1568894226; JSESSIONID=aaaXQbfNVU1rgbPOx94nx; ___rl__test__cookies=1595473000749 Host: fanyi.youdao.com Origin: http://fanyi.youdao.com Referer: http://fanyi.youdao.com/ User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36 X-Requested-With: XMLHttpRequest ''' pattern = '^(.*?): (.*$)' for line in c.splitlines(): print(re.sub(pattern,'\'\\1\': \'\\2\',',line))