centos上使用python执行js代码报错--Could not find an available JavaScript runtime.

文章目录

问题、

我这个是在centos7.2 版本的ecs上执行python代码报错:
报错代码:

Traceback (most recent call last):
  File "3_sub_demand_id_493_search_key.py", line 262, in <module>
    spider_315_search_key_sub_demand_id_532.run_spider_all_key(keyword)
  File "3_sub_demand_id_493_search_key.py", line 62, in run_spider_all_key
    self.get_key_page_data(page, key)
  File "3_sub_demand_id_493_search_key.py", line 88, in get_key_page_data
    get_code = self.get_list_code(data)
  File "3_sub_demand_id_493_search_key.py", line 55, in get_list_code
    ctx = execjs.compile(js_str1)
  File "/usr/local/lib/python3.6/site-packages/execjs/__init__.py", line 61, in compile
    return get().compile(source, cwd)
  File "/usr/local/lib/python3.6/site-packages/execjs/_runtimes.py", line 21, in get
    return get_from_environment() or _find_available_runtime()
  File "/usr/local/lib/python3.6/site-packages/execjs/_runtimes.py", line 49, in _find_available_runtime
    raise exceptions.RuntimeUnavailableError("Could not find an available JavaScript runtime.")
execjs._exceptions.RuntimeUnavailableError: Could not find an available JavaScript runtime.

解决方法:

这个是因为centos上没有安装nodejs环境,不能执行js代码:

yum install epel-release
yum install nodejs

在这里插入图片描述

然后再执行代码即可。

猜你喜欢

转载自blog.csdn.net/weixin_42081389/article/details/106897456