javascript execution from Python script

brueckd at brueckd at
Tue Aug 27 06:39:11 CEST 2002

On Mon, 26 Aug 2002, Justin Guerin wrote:

> 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.

Ahh... well, if you're on Windows then you can automate IE using Mark 
Hammond's win32com extensions, and you can even execute Javascript through 
a web browser object.

Here's a little code to help (untested but I've used similar stuff in the 

import win32com
ie = win32com.client.DispatchEx('InternetExplorer.Application.1')
while ie.Busy:
doc = ie.Document
while not (hasattr(doc, 'readyState') and doc.readyState =='complete'):
pw = doc.parentWindow
pw.execScript("window.alert('foo');") # Your javascript code

Hope this helps,

More information about the Python-list mailing list