473,395 Members | 1,401 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

problem with from win32com.client import Dispatch

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

Nov 22 '05 #1
3 5766
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

Nov 22 '05 #2
thank you so very much robert, now its working after i put the sleep
command.

Nov 22 '05 #3
thank you so very much robert, now its working after i put the sleep
command.

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: selwyn | last post by:
hi, this is my first foray into the mysteries of COM and dlls, so please humour me. I have been provided with a dll interface for a connection to a web-server. The documentation provided is...
1
by: koia | last post by:
Hi, I have a problem with adding attributes to a Line in an Excel drawing using the Python win32com interface. From recording in Excel I get the Macro: Sub Makro1()...
5
by: kbperry | last post by:
On my machine, this runs fine, but when I try to run it on someone elses machine it blows up with an attribute error: <code> import win32com.client, pythoncom ...
3
by: tyler.schlosser | last post by:
Hi there, I am trying to launch a program called AmiBroker using the command: AB = win32com.client.Dispatch("Broker.Application") However, I have a dual-core CPU and would like to launch two...
4
by: mirandacascade | last post by:
O/S : Win2K vsn of Python: 2.4 Hoping to find information that provide information about error messages being encountered. Pythonwin session: Traceback (most recent call last): File...
4
by: vithi | last post by:
Hi' I am trying to launch an application. When I try like that When I try like that Excel is opening import win32com.client object = win32com.client.Dispatch("Excel.Application") object.Visible...
2
by: Ray | last post by:
Hi, I need to use cell's background color. when I record a macro from excel, it shows: Rows("7:7").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid
0
by: Ramdas | last post by:
How do I trap errors from win32com.client. I have tried the com_error classes from pywintypes and pythoncom sub modules. It is not catching for all cases. Is there any docs available?
3
by: Amelie Lesser | last post by:
Hello, I'm trying to use the in32com.client for writing into Excel with Dispatch() (on a windows machine using python 2.7.1). I downloaded pywin from http://sourceforge.net/projects/pywin32/ into...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.