python js脚本特殊字解析报异常问题处理,execjs.compile
def _read_js_file(): """ 读js文件 :return: 返回js文件内容 """ f = open("decode.js", 'r', encoding='utf-8') # 打开JS文件 line = f.readline() str_file = '' while line: str_file = str_file + line line = f.readline() return str_file __js_str =_read_js_file() js_compile = execjs.compile(__js_str) js_input ="=_省略.....;" js_result = js_compile.call('decode', js_input) print(js_result)
会提示:
SyntaxError: Non-UTF-8 code starting with '\xef' in file F:xxxx.py on line 34, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details
如下增加r,指定raw字符串,就可以成功执行js
posted on 2022-04-19 10:58 Shine-Zhong 阅读(596) 评论(0) 编辑 收藏 举报