在PyCharm中使用execjs模块执行js文件时报错

错误说明:

在PyCharm中使用execjs模块执行js文件时报错
Exception in thread Thread-1:
Traceback (most recent call last):
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\threading.py", line 980, in _bootstrap_inner
    self.run()
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\threading.py", line 917, in run
    self._target(*self._args, **self._kwargs)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\subprocess.py", line 1479, in _readerthread
    buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position 135: illegal multibyte sequence
Traceback (most recent call last):
  File "D:\PycharmProjects\网络爬虫\逆向爬虫\demo2.py", line 38, in <module>
    ctx = execjs.compile(jquery_code).call('s',encrypt_data)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call
    return self._call(name, *args)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_external_runtime.py", line 92, in _call
    return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args))
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_external_runtime.py", line 78, in _eval
    return self.exec_(code)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_
    return self._exec_(source)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_external_runtime.py", line 88, in _exec_
    return self._extract_result(output)
  File "D:\ProgramData\anaconda3\envs\web_crawlers\lib\site-packages\execjs\_external_runtime.py", line 156, in _extract_result
    output = output.replace("\r\n", "\n").replace("\r", "\n")
AttributeError: 'NoneType' object has no attribute 'replace'
demo2.py文件
import requests
import execjs

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Origin': 'https://www.qimingpian.com',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'cross-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188',
    'sec-ch-ua': '"Not/A)Brand";v="99", "Microsoft Edge";v="115", "Chromium";v="115"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

data = {
    'time_interval': '',
    'tag': '',
    'tag_type': '',
    'province': '',
    'lunci': '',
    'page': '1',
    'num': '20',
    'unionid': '',
}

response = requests.post('https://vipapi.qimingpian.cn/DataList/productListVip', headers=headers, data=data).json()
encrypt_data = response['encrypt_data'] # 密文数据

# 加载jQuery库
with open("./demo2
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值