Re: javascript interpreter in perl???
by plobsing (Friar) on Feb 05, 2008 at 08:37 UTC
|
By "solve javascripts" do you mean view the content of a heavily js'ed/ajaxed page? In that case:
Javascript engines:
As for actually using javascript inside real world webpages (malformedness problems, etc), you are probably best automating a browser (Win32::IE::Mechanize, etc), but theres also WWW::Mechanize::Plugin::JavaScript
Of course you could have found all that with a super search and a quick look at cpan. | [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by Erez (Priest) on Feb 05, 2008 at 09:44 UTC
|
| [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by bart (Canon) on Feb 05, 2008 at 12:00 UTC
|
If you use the module Win32::IE::Mechanize on Windows as an alternative for WWW::Mechanize then it'll execute the Javascript on the web pages it fetches. That happens due to the fact that this module uses the MSIE core to fetch the web pages.
Nevertheless, the idea of being able to use Javascript from within perl (thus, without using a browser core) and have it being able to use the DOM to process a html page does appeal to me. I'd prefer to have some tie-like mechanism for variables and object fields in Javascript, which invokes routines in Perl. Chalk it up on the wishlist... | [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
I'm interested in looking into this, even though I've never used JavaScript::SpiderMonkey in my life. So it's going to take a while.
I see you've started looking into HTML::TagParser, and as I currently have some interest in HTML::Tree due to current work on another module (where most work is being done by grandfather), I'm interested of trying that route.
But don't hold your breath. :)
| [reply] [Watch: Dir/Any] |
|
Hi.. Tried it with Win32::IE::Mechanize in windows and i was able to get the code.. thanks a lot :)But want it in unix as the main workin platform is that. so still tryin to find a way to access web page and process the javascripts that occur in that. However thanks a ton for the help :)
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: javascript interpreter in perl???
by McDarren (Abbot) on Feb 05, 2008 at 08:32 UTC
|
| [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by marcussen (Pilgrim) on Feb 05, 2008 at 09:42 UTC
|
| [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by Starky (Chaplain) on Feb 05, 2008 at 14:46 UTC
|
| [reply] [Watch: Dir/Any] |
|
my excessive usage of sms brought in such a language.. sorry about that.. (or sry abt tat :) )
| [reply] [Watch: Dir/Any] |
Re: ny JavaScript interpreters in perl???
by ikegami (Patriarch) on Feb 05, 2008 at 08:52 UTC
|
| [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by gam3 (Curate) on Feb 06, 2008 at 04:44 UTC
|
Note that an interpreter is not all you need to solve this problem. You need to have a DOM as well.
Depending on what you want to do this can be hard or easy.
-- gam3
A picture is worth a thousand words, but takes 200K.
| [reply] [Watch: Dir/Any] |
|
Can you please tell me how to get a DOM for working on the web page??
I tested the JE module and it was able to solve javascripts.. but I not sure how to test it connected with a web page.. i mean, the module was able to solve simple scripts like
function xxx() {
return 42;
}
but i do not know how to test it for scripts that access the DOM. for example. the script has statements like document.getElementByID etc. how do i create the handle of the retrieved web page as 'document'..
can u please suggest me on this..
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: javascript interpreter in perl???
by Anonymous Monk on Jun 28, 2010 at 00:19 UTC
|
Here's my little Javascript Perl Interpreter. It's much easier than you think.
#!/usr/bin/perl
######################################################################
+#########
# JtoP.cgi
+ #
#
+ #
# This program is distributed in the hope that it will be useful,
+ #
# but WITHOUT ANY WARRANTY; without even the implied warranty of
+ #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ #
# GNU General Public License for more details.
+ #
#
+ #
#
+ #
# Last modified: 06/27/10
+ #
######################################################################
+#########
# Set-up the cgi enviroment
# this little gizmo is something I adopted
# and works like a champ
use CGI;
$query = new CGI;
@names = $query->param;
foreach $parameter (@names) {
$_ = $query->param($parameter);
$input{$parameter} = $_;
}
# we won't have this until the Ajax kicks in after page load
# then it happens quietly behind the scenes
if ($_) {
$screenwidth = $input{'screenwidth'};
$screenheight = $input{'screenheight'};
$availwidth = $input{'availwidth'};
$availheight = $input{'availheight'};
$screen = "$input{'screenwidth'} x $input{'screenheight'}";
$availscreen = "$input{'availwidth'} x $input{'availheight'}";
$colordepth = $input{'colordepth'};
open(FILE, ">>foobat.txt");
print FILE "$screen\n";
print FILE "$availscreen\n";
print FILE "$colordepth\n";
close FILE;
}
# no HTML here just get to the Ajax and send the data
print "content-type: text/html\n\n";
print qq~
<script type="text/javascript">
// OOAjax thanks to Patrick Hunlock
function ajaxObject(url, callbackFunction) {
var that=this;
this.updating = false;
this.abort = function() {
if (that.updating) {
that.updating=false;
that.AJAX.abort();
that.AJAX=null;
}
}
this.update = function(passData,postMethod) {
if (that.updating) { return false; }
that.AJAX = null;
if (window.XMLHttpRequest) {
that.AJAX=new XMLHttpRequest();
} else {
that.AJAX=new ActiveXObject("Microsoft.XMLHTTP");
}
if (that.AJAX==null) {
return false;
} else {
that.AJAX.onreadystatechange = function() {
if (that.AJAX.readyState==4) {
that.updating=false;
that.callback(that.AJAX.responseText,that.AJAX.status,that.A
+JAX.responseXML);
that.AJAX=null;
}
}
that.updating = new Date();
if (/post/i.test(postMethod)) {
var uri=urlCall+'?'+that.updating.getTime();
that.AJAX.open("POST", uri, true);
that.AJAX.setRequestHeader("Content-type", "application/x-www-
+form-urlencoded");
that.AJAX.setRequestHeader("Content-Length", passData.length);
that.AJAX.send(passData);
} else {
var uri=urlCall+'?'+passData+'×tamp='+(that.updating.getT
+ime());
that.AJAX.open("GET", uri, true);
that.AJAX.send(null);
}
return true;
}
+
}
var urlCall = url;
this.callback = callbackFunction || function () { };
}
// get the variables
//var sw = document.getElementById("screenwidth").value;
//var sh = document.getElementById("screenheight").value;
//var aw = document.getElementById("availwidth").value;
//var ah = document.getElementById("availheight").value;
//var cd = document.getElementById("colordepth").value;
var sw = screen.width;
var sh = screen.height;
var aw = screen.availWidth;
var ah = screen.availHeight;
var cd = screen.colorDepth;
// the Ajax object
var myRequest = new ajaxObject('JtoP.cgi');
// the query string
var sendString = 'screenwidth='+sw+'&screenheight='+sh+'&availwidt
+h='+aw+'&availheight='+ah+'&colordepth='+cd;
// and go man go
myRequest.update(sendString,'POST');
</script>
~;
1;
It works without form fields. It send the javascript data straight to Perl upon page load. Maybe too simple but it works like a charm.
Ted Cambron
tedcambron@hotmail.com | [reply] [Watch: Dir/Any] [d/l] |
|
| [reply] [Watch: Dir/Any] |
|
Call it what you will. It works and a whole lot better than any solution you have given.
| [reply] [Watch: Dir/Any] |
|