[python-win32] win32com and GetRef

Mark Hammond mhammond at skippinet.com.au
Thu Nov 3 02:45:39 CET 2005


> I'm using win32com to manipulate the DOM inside of Internet
> Explorer. Something like this:
>
> #-----------------------------------------------------------------
> ----------
> import win32com.client
>
> ie = win32com.client.Dispatch('InternetExplorer.Application')
> ie.Navigate('about:about')
> body = ie.Document.getElementsByTagName("BODY")[0]
>
> #
> # Now comes the tricky part, I need to supply a "pointer-to-a-function"
> #
> def init():
>      pass
>
> body.onload = init        # XXXXXX Problem here

You need to have a look at win32com.client.DispatchWithEvents.  Python takes
a different approach to hookup events.

>>> import win32com.client
>>> help(win32com.client.DispatchWithEvents)

> Further Question: if its not possible would I be able to do this
> using Mozilla and pyxcom?

Not from an external process, no - xpcom does not work across processes.  If
you wanted to write a Mozilla extension (ie, some "chrome"), then other work
I am doing with the Mozilla guys will soon make this possible - you will be
able to use Python whereever you can currently use JS - but that's a
different story <wink>

Mark



More information about the Python-win32 mailing list