problem with from win32com.client import Dispatch

M

muttu2244

Hi all

Am trying to read an html page using win32com in the following way.



from win32com.client import Dispatch

ie = Dispatch("InternetExplorer.Application")

ie.Navigate("https://secure.authorize.net/")

doc =ie.Document

print doc.body.innerHTML



with this code am easily able to read the mentioned page from the
pythonwin interactive window, but the same code if I write it in some
*.py file, am not able to read the page.



The following error it throws when I compile the file.



Traceback (most recent call last):

File
"C:\Python23\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript

exec codeObject in __main__.__dict__

File "C:\Python23\Lib\site-packages\Script1.py", line 14, in ?

ie.Quit()

File "C:\Python23\Lib\site-packages\win32com\client\__init__.py",
line 456, in __getattr__

return self._ApplyTypes_(*args)

File "C:\Python23\Lib\site-packages\win32com\client\__init__.py",
line 446, in _ApplyTypes_

return self._get_good_object_(

com_error: (-2147352567, 'Exception occurred.', (0, None, None, None,
0, -2147467259), None)



if any body has the answer for this please help me in this.



Thanks and regards

Yogi
 
C

calfdog

Hello,

If you want some goood examples of reading Web pages and automating
this process
I have a class that wraps all these functions.

http://pamie.sourceforge.net

But for your problem:
You are trying to read the page before it is completely loaded

either add a wait function or a simple sleep ( see below)

from win32com.client import Dispatch
import time

ie = Dispatch("InternetExplorer.Application")

ie.Navigate("https://secure.authorize.net/")
# ie.Visible = True


time.sleep(1)
doc = ie.Document

print doc.body.innerHTML


or with a wait function

from win32com.client import Dispatch
import time


def wait(ie):
while ie.Busy:
time.sleep(0.5)
while ie.Document.readyState != "complete":
time.sleep(0.5)

ie = Dispatch("InternetExplorer.Application")

ie.Navigate("https://secure.authorize.net/")
# ie.Visible = True

wait(ie)

doc = ie.Document

print doc.body.innerHTML


Enjoy
Robert Marchetti
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top