在尝试爬取该数据的时候,通过分析源码找到了加密的函数webInstace,进入该函数之后将整个webInstace的源码通过ctrl+A复制下来并整成js文件,但在代码运行的时候报了这两个错误。
在单步调试的时候,webInstace函数中传入的参数显示为f(_0xa0c834),而在源码最后也能得到该结果,但这段源码复制到开发者工具中的console中运行就报了
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/584125814566157.png "#left")
Uncaught SyntaxError: Invalid or unexpected token at <anonymous>:1:18
的错误,请问应该怎么解决??
下面是源代码:
import requests
import execjs
url = 'https://www.endata.com.cn/API/GetData.ashx'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36'
}
data = {
'year':'2022',
'MethodName':'BoxOffice_GetYearInfoData'
}
res = requests.post(url,data=data,headers=headers,timeout=5)
restext = res.text
with open('jsdata.js','r',encoding='utf-8') as f:
js = f.read()
# print(js)
resp = execjs.compile(js)
response = resp.call('webInstace.shell',restext)
print(response)
报错信息:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1267, in _readerthread
buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa5 in position 112: illegal multibyte sequence
Traceback (most recent call last):
File "C:/Users/24681/Desktop/python file/caicai/untitled/爬虫/JS逆向/艺恩电影票房.py", line 19, in <module>
response = resp.call('webInstace.shell',restext)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
return self._call(name, *args)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_external_runtime.py", line 92, in _call
return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
return self.exec_(code)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
return self._exec_(source)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_external_runtime.py", line 87, in _exec_
output = self._exec_with_pipe(source)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\site-packages\execjs\_external_runtime.py", line 103, in _exec_with_pipe
stdoutdata, stderrdata = p.communicate(input=input)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 964, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Users\24681\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1317, in _communicate
stdout = stdout[0]
IndexError: list index out of range