How does python execute the javascript code and get the console output of js?

this library can execute js, but cannot get console output
https://pypi.org/project/PyEx.

seems to be a similar problem:
from-python" rel=" nofollow noreferrer "> https://stackoverflow.com/que.

Apr.26,2021

cannot be executed directly, so why don't you change your way of thinking, open the browser through selenium and execute it in the browser, then you can get everything you want.


what about the answer on

Stack Overflow?


if you only take the console output, you can call nodejs to execute javascript, such as

-sharp -*- coding: utf-8 -*-
from subprocess import Popen, PIPE

script = '''
console.log('hi');
'''

p = Popen(['node'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
out, err = p.communicate(script.encode())
print(f'{out}\n{err}\n')
Menu