Is there a way to execute JavaScript in Perl?

后端 未结 5 900
眼角桃花
眼角桃花 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:15

    TMTOWTDI. Another option is WWW::Scripter, with the Javascript or AJAX plugin.

    0 讨论(0)
  • 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)'

    0 讨论(0)
  • 2020-12-03 23:31

    There is also Win32::IE::Mechanize, Mozilla::Mechanize. But the previously mentioned WWW::Selenium is the most DWIW and well-supported if you have access to browsers and can run the Selenium server. Selenium is a Java critter that runs the browser interactions for you. It has IDEs for several browsers and can write code for you—by recording browser actions—in several languages including Perl or you can hand write it. It’s test-centric, where it excels, but there is no reason not to be use it for general automation/scraping.

    0 讨论(0)
  • 2020-12-03 23:32

    WWW::Selenium?

    0 讨论(0)
  • 2020-12-03 23:38

    Would you mean something like JavaScript::SpiderMonkey, a Perl interface to a JavaScript engine used by Mozilla?

    0 讨论(0)
提交回复
热议问题