Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Actually executing JS within Perl?

10:29 pm on Dec 15, 2008 (gmt 0)

5+ Year Member

Here's my scenario:
There's an html page on my server that contains a link to a javascript source file (on another server). This javascript file returns/places an image in the html page from which the javascript file was src'd. Included javascript looks basically like this:

<script type="text/javascript"><!--
setup_all_parameters = "parameters";
<script type="text/javascript"

That returns an image inline when viewing in a browser.

Within a Perl CGI on my server, I'd like to see the url for the image returned by the javascript described above. How can I execute/evaluate the javascript from within Perl to get the image url it returns?

LWP's get() just returns the source of the file without client-side processing. Can I pipe it to some virtual machine and get back the output?

11:01 pm on Dec 15, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

you can, but you propably don't want to, because it'll be painfull and insecure. And you probably don't have to: just figure out how the javascript works, then just parse the script with a regular expression and construct the imageurl you need.
11:42 pm on Dec 15, 2008 (gmt 0)

5+ Year Member

I can't figure out how the script assembles the url. It's Google's AdSense script for displaying ads. I need to do some processing based on the image ad urls it's returning to my site.

Here's the link to the code (some random website):i

<script type="text/javascript"><!--
google_ad_client = "pub-6666777788889999";
/* 728x90image */
google_ad_slot = "0541304911";
google_ad_width = 728;
google_ad_height = 90;
<script type="text/javascript"

If anyone has/can parsed it successfully, I'd love to know how.

[edited by: huesv at 12:26 am (utc) on Dec. 16, 2008]

12:19 am on Dec 16, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

you could try playing with the google adsense preview tool. If I recall correctly (been a few years since I wrote a script using it), there is an API that will return ads for any page or keyword in test-mode. use the preview tool, find the api (or find it by searching the web, it's been done before, look for adsense sandbox and similar keywords) and see wether it returns images as well (I know for sure it gives you those text-ads, image-ads hadn't been around when I played with it).

btw, you might want to remove the google-clientid etc from your post, it's not wise if it's yours and it's not nice if it's not yours.


Featured Threads

Hot Threads This Week

Hot Threads This Month