Using win32Com with Internet Explorer

cborn at swbell.net cborn at swbell.net
Sun Feb 18 09:10:33 CET 2001


I am fairly new to Python and Com programming so hopefully
this will be simple.

Here is a script I have written which attempts to extract
links from a webpage. I have used makepy to generate Python
IE support object (Msie ActiveX control Module 1.0).



import win32com.client

# Get the browser object
ie = win32com.client.Dispatch("InternetExplorer.Application")
# open a page
ie.Navigate("http://www.python.org")

i = 0
# Get links from IE's Document Object
for x in ie.Document.links:
        #Print links
 	print ie.Document.links(i)
 	i = i +1



When I run the script in PythonWin this is what I get:



Traceback (most recent call last):
  File "C:\Python20\Pythonwin\pywin\framework\scriptutils.py", line 
301, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Python20\CB\test.py", line 12, in ?
    for x in ie.Document.links:
  File "C:\Python20\win32com\client\__init__.py", line 340, in 
__getattr__
    return apply(self._ApplyTypes_, args)
  File "C:\Python20\win32com\client\__init__.py", line 334, in 
_ApplyTypes_
    return self._get_good_object_(apply(self._oleobj_.InvokeTypes, 
(dispid, 0, wFlags, retType, argTypes) + args), user, resultCLSID)
com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 
0, -2147467259), None)


However, when I enter the script interactively 1 line at a time it 
works. I am sure there is some small detail that I am 
missing. Can anyone help me?

Thanks

Charles Bornstein
cborn at swbell.net





More information about the Python-list mailing list