Is there a way to execute JavaScript in Perl?

后端 未结 5 907
眼角桃花
眼角桃花 2020-12-03 23:07

I\'ve worked some years now in Perl building Web scrapers, and given the problem that spam represents, and how scraping Web pages would turn out to be much more easier to th

5条回答
  •  再見小時候
    2020-12-03 23:30

    You can try to install SpiderMonkey and -in your perl program- execute javascript in backticks, and capture the result, just like from any other unix command line tool. Spidermonkey has a command line option for that, similar to perl's -e command line option. The spidermonkey binary is called "js", thus:

    /path/to/spidermonkey/bin/js -e "print(10);"

    > 10

    I think you can also install v8-shell as an alternative engine, but then you must install 'scons' first, which is available on unix-only.

    ./v8-shell -e 'print("10*10 = " + 10*10)'

提交回复
热议问题