Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using win32Com with Internet Explorer

650 views
Skip to first unread message

cb...@swbell.net

unread,
Feb 18, 2001, 3:10:33 AM2/18/01
to pytho...@cwi.nl
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
cb...@swbell.net


Mark Hammond

unread,
Feb 18, 2001, 5:52:06 PM2/18/01
to
cb...@swbell.net wrote:

> 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).

...

> 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?

Probably you need to wait for IE to load the page. There was an example of that posted a few days ago here that used events - basically you wait until IE tells you the page is loaded.

Mark.

--
Nominate Your Favorite Programmers
for the Perl and Python Active Awards!
http://www.ActiveState.com/Awards/

David Fuess

unread,
Feb 19, 2001, 10:51:27 AM2/19/01
to
Pardon my directness, but isn't it rather foolish to go messing around
with IE and COM when Python provides libraries for this purpose. I've
implemented many crawlers using urllib, httplib, and htmllib to fetch,
parse, and follow URL threads.

Dave

On Sun, 18 Feb 2001 22:52:06 GMT, Mark Hammond <Ma...@ActiveState.com>
wrote:

Toby Dickenson

unread,
Feb 19, 2001, 1:31:05 PM2/19/01
to
David Fuess <fu...@att.net> wrote:

>Pardon my directness, but isn't it rather foolish to go messing around
>with IE and COM when Python provides libraries for this purpose. I've
>implemented many crawlers using urllib, httplib, and htmllib to fetch,
>parse, and follow URL threads.

For many cases the IE-based code is better. For example, it uses IE's
proxy configuration and local cache.

If you need to redistribute a script to someone else, then a working
IE configuration is probably something you can rely on.

Toby Dickenson
tdick...@geminidataloggers.com

David Fuess

unread,
Feb 20, 2001, 11:25:39 PM2/20/01
to
Now trhat I've had a day to think about it, I must respectfully
disagree. I think the one, and only, thing you can count on is the
Pyrhon libraries. The urllib has a FancyOpener that understands
proxies and is simple and stable. IE is neither simple nor stable
particularly as you never know what version will be installed on the
target machine. Further, httplib and htmllib give you complete control
over the decoding of the web pages.

I use the same code on Windows, UNIX, and Macintosh systems. Neither
UNIX nor the Mac have IE, yet all were capable of retrieving and
decoding web pages with no changes in the code. If you write in COM
you are restricted to Windows platforms only.

Dave

Fredrik Lundh

unread,
Feb 21, 2001, 1:54:26 AM2/21/01
to
Toby Dickenson wrote:
> For many cases the IE-based code is better. For example, it uses IE's
> proxy configuration

so does Python

Cheers /F


Toby Dickenson

unread,
Feb 21, 2001, 8:09:43 AM2/21/01
to
"Fredrik Lundh" <fre...@pythonware.com> wrote:

Yes, it does make a good effort (thanks Mark!)

However, many proxy configurations are implemented using a javascript
function that computes the proxy configuration.


On Wed, 21 Feb 2001 04:25:39 GMT, David Fuess <fu...@att.net> wrote:

>I use the same code on Windows, UNIX, and Macintosh systems. Neither
>UNIX nor the Mac have IE, yet all were capable of retrieving and
>decoding web pages with no changes in the code.

Im pretty sure it wont work on my current machine, without manual
proxy configuration.

>If you write in COM
>you are restricted to Windows platforms only.

Yes, it depends on your requirements. I didnt intent to suggest that
IE/COM is always superior to httplib.

My current http client project uses COM/IE if it can, but falls back
to httplib. Both modes of operation have been necessary at some time.

Fredrik Lundh

unread,
Feb 21, 2001, 1:06:32 PM2/21/01
to
Wolfgang Strobl wrote:
> >so does Python
>
> Huh? Python uses IE's proxy configuration? How?

by looking in the registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Internet Settings\ProxyEnable, ProxyServer

Cheers /F


0 new messages