python运行js代码:
import execjs
with open('js代码.txt', 'r', enconding = 'utf-8') as fp:
js_text=fp.read()
text = execjs.compile(js_text).call(hanshu, para1, para2)
请求头加引号:
header_all = """
access-control-allow-credentials: true
access-control-allow-headers: *
access-control-allow-methods: *
access-control-allow-origin: http://tool.liumingye.cn
access-control-max-age: 3600
content-type: application/json; charset=utf-8
date: Fri, 28 Aug 2020 16:02:44 GMT
server: nginx
status: 200
"""
pattern = '^(.*?):(.*?)$'
for line in header_all.splitlines():
print(re.sub(pattern, '\'\\1\':\'\\2\',', line))