2000: A Win32 Oddisey

Michal Wallace sabren at manifestation.com
Sat Sep 23 23:55:12 CEST 2000

On Sat, 23 Sep 2000, Pedro wrote:

> > I've never tried this... but... maybe you can use the IE browser
> > component via COM?
> What module I have to import?. Was looking at the library ref. but found
> nothing!

you need the win32 extensions, for one thing..
once you have them:

  - open pythonwin
  - load the "COM Makepy utility" under the Tools menu
  - in the window that pops up, double click on:
     "Microsoft Internet Controls"

This generates a magical python module for you.. Now, in
the python window, type:

>>> from win32com.client import Dispatch
>>> ie = Dispatch("InternetExplorer.Application")
>>> ie.Visible = 1

At this point, if things are going well, a browser will appear,
but will have no content... So.. let's go someplace secure:

>>> ie.Navigate("https://secure.authorize.net/")

... Well, it shows up in the browser... But how to get the

In pythonwin, go to "Tools/COM Browser"
"Registered Type Libraries"
    "Microsoft Internet Controls"
        "Type Library"
            "InternetExplorer - CoClass"

.. That didn't help...

>>> ie
<win32com.gen_py.Microsoft Internet Controls.IWebBrowser2>


"Tools/COM Browser"
    "Registered Type Libraries"
        "Microsoft Internet Controls"
            "Type Library"

Hmmm. That seems to show a bit more info, but we still don't
know what to do with it.. Let's go to msdn and see if we can
look that control up... Here it is:


Looks like we want the "get Document" thing. Back to python.

>>> ie.Document
<COMObject Document>


>>> doc = ie.Document

According to the MSDN docs, this is just a normal DHTML document

>>> doc.url

>>> print doc.body.innerHTML
[it works!]

doesn't print the WHOLE HTML document, granted, just the body..  but
you can basically script it as if it were client side DHTML because
you're using the same engine. You may not need to grab it..


Anyway, to get rid of it:

>>> del doc
>>> ie.Quit()


- Michal
www.manifestation.com  www.sabren.com  www.linkwatcher.com  www.zike.net

More information about the Python-list mailing list