in reply to Re: SpiderMonkey and JS
in thread SpiderMonkey and JS

well...I think I'm still missing something...
use warnings; use strict; use LWP::UserAgent; use HTML::Parser; use JavaScript::SpiderMonkey; use Data::Dumper; my $base = 'http://www.myspace.com'; my $js = JavaScript::SpiderMonkey->new(); $js->init(); $js->function_set("SMSTokenValue", sub { print "@_\n"; }); $js->property_by_path("document.getElementById"); { my $ua = new LWP::UserAgent(); my $req = new HTTP::Request ('GET', $base); my $res = $ua->request($req); if (!($res->is_success)){ warn "Warning:".$res->message."\n"; } else { print "Successful\n"; $js->property_by_path("document.location.href"); my $rc = $js->eval(q! document.location.href = append("http://", "www.myspace.com"); document.getElementById = append("ctl00_ctl00_cpMain_cpMain_LoginB +ox_SMSVerifiedCookieToken"); SMSTokenValue("Token: ", document.getElementById); function append(first, second) { return first + ' = ' + second; } !); $js->destroy(); } }
The value comes back as undefined...Am I missing something else?

Replies are listed 'Best First'.
Re^3: SpiderMonkey and JS
by spx2 (Deacon) on May 01, 2009 at 22:37 UTC
      $js->property_by_path("document.location.href");

    here you're not actually setting aything , please read here how property_by_path is properly used.

    document.location.href = append("http://", "www.myspace.com"); document.getElementById = append("ctl00_ctl00_cpMain_cpMain_LoginB +ox_SMSVerifiedCookieToken");

    if you would have used property_by_path correctly above there would've been no need for setting location.href again inside javascript . however if you decide to do it in js you need to keep in mind that it won't take effect immediately and you must somehow wait until the page is loaded.

    P.S. see this tutorial by Limbic~Region where he describes how WWW::Selenium is used in a similar situation.