win32com and internet explorer

Jose Correia correia_j at hotmail.com
Thu Jul 4 22:22:30 EDT 2002


Don't know how to get the entire page saved to disk, but hopefully this gets
you a little closer to your goal if you're trying to get at the info on the
page.

>>> from win32com.client import Dispatch
>>> ie = Dispatch("InternetExplorer.Application")
>>> ie.Navigate("http://www.google.com")
>>> ie.Visible=1
>>> ie.Document.body.innerHTML
'<CENTER>\015\012<TABLE cellSpacing=0 ........'

... this gives you all the html between the BODY tag in a string, you just
don't get the Header bit.  I'm sure there's a way to get it all but I
haven't been able to find it yet.  If you find it let me know.

If you're trying to submit info on the page you need to look at the source
to see the object names.
For example, a secure site I use has a form (called frmLogin) to enter an
account number (field called: Account)
and password (field called: Password).

The code I use looks like this:
doc = ie.Document
doc.forms(0).Account.value = "987654321"        # Referenced as the first (0
based count) form on the page.
sleep(0.5)                            # Otherwise it seems to run too fast
and get confused :-(
doc.frmLogin.Password.value = "some_password"    #Referenced by the form's
name in the HTML.
sleep(0.5)
doc.forms(0).submit()        # Sends the info.
sleep(1)

You can check if it's finished processing by checking if
ie.ReadyState == 4         and
doc.readyState == "complete"

For further info on the MS stuff try:
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/ref
erence/objects/obj_document.asp

and
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrows
er/reference/ifaces/IWebBrowser2/IWebBrowser2.asp


HTH,

Jose






More information about the Python-list mailing list