MSIE6 Python Question

calfdog at calfdog at
Thu Jun 3 00:19:15 CEST 2004

r.gable at (Ralph A. Gable) wrote in message news:<22b7fd40.0405231744.50d125f1 at>...
> I'm a newbie at this but I need to control MSIE6 using Python. I have
> read the O'Reilly win32 python books and got some hints. But I need to
> Navigate to a site (which I know how to do) and then I need to get at
> the source code for that site inside Python (as when one used the
> View|Source drop down window). Can anyone point me to some URLs that
> would help out? Or just tell me how to do it? I would be very
> grateful.


from win32com.client import DispatchEx  

import time

def wait(ie): # very important!!! you have to wait for each page to load
    "Given an IE object, wait until the object is ready for input."
    while ie.Busy: time.sleep(0.1)
    doc = ie.Document
    while doc.ReadyState != 'complete': time.sleep(0.1)
    return doc

def ClickLink(ie, mylink):
    #hrefs = []
    for link in ie.Document.links:
        if link is None: break # needed for browser bug

        if link.innerText == mylink:

# Here is what you need
ie = DispatchEx('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate ('')

# Some extra
wait(ie)# Very important you must wait for document to finish loading


More information about the Python-list mailing list