javascript execution from Python script

Cameron Laird claird at starbase.neosoft.com
Tue Aug 27 09:16:15 EDT 2002


In article <mailman.1030391201.29388.python-list at python.org>,
Justin Guerin  <jguerin at cso.atmel.com> wrote:
>On Monday 26 August 2002 12:10 pm, Matt Gerrans wrote:
>> Java and JavaScript are entirely different and unrelated animals; the fact
>> that they have similar names is just the result of a horrible marketing
>> blunder.  
Only programmers regard it as a blunder.
			.
			.
			.
>
>I had no idea they were THAT unrelated.
They share some syntax, including keywords.
That was done mostly for intellectually
illegitimate reasons.
>
>> Jython is very nifty and allows you to call Java from Python and
>> vice versa (in fact, regarding the eternal question of Tkinter vs.
>> wxWindows et al, I am beginning to like the idea of using Swing via
>> Jython), but from what you've said it looks like you are really more
>> interested in JavaScript, not Java.
>>
>> What exactly are you trying to accomplish?
>
>I administer a 3rd party software program that has a web based interface.  I 
>want to automate some of the repetitive tasks I find myself doing often, but 
>I can't get directly to the internals, so I figured I could write a script to 
>drive the web based interface.  Many pages contain javascript, and most of 
>the scripting can be done by massaging the javascript source, but as for the 
>rest, I'd rather not write unique code for it.  After all, I can't really 
>control when the interface changes.
Ugh.

I applaud your instincts:  automate those repetitive
tasks.

Key facts:  while it's feasible to write a JavaScript
interpreter in Python, no one's done so, to my knowledge.
You're absolutely right that your vendor could trick up
the page at any time.  This makes it sound rather hopeless.

It's actually both better and worse than this.
JavaScript adds nothing, in a dataflow sense; if you
read the page carefully, you'll find that you can get
at all the information you need without JavaScript.
It's fairly common, in fact, for the visual display
to suffer profound changes, with much different
JavaScript coding, while the underlying content, which
is what you're after, remains invariant.

With one exception:  the one serious problem JS intro-
duces is that it can invoke Java code, generally to
"call home" through a network connection.  If that's
happening, you've got a serious challenge ahead of you.
The good news, in that case, is that a JS interpreter
wouldn't help you anyway; you'd need Java as well.

I do this kind of Web scraping occasionally.  I
generally find it worthwhile, by hand; the benefits of
the automation are worth the cost of deciphering the
JavaScript "by hand".

There are also commercial JavaScript interpretive
engines available, but, unless you have a serious
budget, I recommend against them.
			.
			.
			.

-- 

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://starbase.neosoft.com/~claird/home.html



More information about the Python-list mailing list