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
> 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/
Dave
On Sun, 18 Feb 2001 22:52:06 GMT, Mark Hammond <Ma...@ActiveState.com>
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
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
so does Python
Cheers /F
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.
by looking in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\
CurrentVersion\Internet Settings\ProxyEnable, ProxyServer
Cheers /F