Is there a way to execute JavaScript in Perl?

I worked for several years in Perl, creating web scrapers, and given the problem that spam poses and how scraping web pages turn out to be much easier for these people if, for example, Perl LWP :: UserAgent can handle its javascript cup, I amazed that no one has created a JS engine for him yet.

What am I missing here?

Thanks in advance. Best wishes.

PS: I'm not a spammer. Just curious.

+6
javascript perl
source share
5 answers

Could you mean something like JavaScript :: SpiderMonkey , the Perl interface for the JavaScript engine used by Mozilla?

+8
source share
+6
source share

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

+6
source share

There is also Win32 :: IE :: Mechanize , Mozilla :: Mechanize . But the previously mentioned WWW :: Selenium is the most DWIW and is well supported if you have access to browsers and you can start the Selenium server. Selenium is a Java twitter that launches browser interaction for you. It has an IDE for several browsers and can write code for you - by writing browser actions in several languages , including Perl, or you can write it. Its test-centric where it excels, but there is no reason not to use it for general automation / scrapers.

+4
source share

You can try installing SpiderMonkey and - in your perl program - execute javascript in backticks and get the result like any other unix command line tool. Spidermonkey has a command line option similar to the perl -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 first install "scons", which is available only for unix.

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

+4
source share

All Articles