473,748 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Inter netExplorer.App lication")

ie.Navigate("ht tps://secure.authoriz e.net/")

doc =ie.Document

print doc.body.innerH TML

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\Li b\site-packages\python win\pywin\frame work\scriptutil s.py",
line 310, in RunScript

exec codeObject in __main__.__dict __

File "C:\Python23\Li b\site-packages\Script 1.py", line 14, in ?

ie.Quit()

File "C:\Python23\Li b\site-packages\win32c om\client\__ini t__.py",
line 456, in __getattr__

return self._ApplyType s_(*args)

File "C:\Python23\Li b\site-packages\win32c om\client\__ini t__.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 5855
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("Inter netExplorer.App lication")

ie.Navigate("ht tps://secure.authoriz e.net/")
# ie.Visible = True
time.sleep(1)
doc = ie.Document

print doc.body.innerH TML
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.rea dyState != "complete":
time.sleep(0.5)

ie = Dispatch("Inter netExplorer.App lication")

ie.Navigate("ht tps://secure.authoriz e.net/")
# ie.Visible = True

wait(ie)

doc = ie.Document

print doc.body.innerH TML
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
1493
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 clear that the dll requires the server config file to be in same folder as the dll. I know the dll is installed and registered properly, as is the server
1
3719
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() ActiveSheet.Shapes.AddLine(192.75, 63.75, 316.5, 110.25).Select Selection.ShapeRange.Line.ForeColor.SchemeColor = 10 Selection.ShapeRange.Line.Visible = msoTrue
5
21964
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 pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED) myWord = win32com.client.dynamic.Dispatch ("Word.Application") myWord.Visible = True myDoc = myWord.Documents.Open(FileName= "C:\Test.doc")
3
6948
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 instances of AmiBroker. I know it is possible to run two instances simultaneously since it is easy to do manually by double-clicking the AmiBroker.exe file twice. However, when I write two lines of code like this:
4
6905
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 "<interactive input>", line 1, in ?
4
17096
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 = 1 But when I try my application which is QeepIt.exe which is in the c:\ drive it is not running Any body tell me how to give path to open an exectable application in
2
9285
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
1122
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
15252
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 the C:\Python27 folder and hit both setup.py and pywin32_postinstall.py I'm running my python program in the windows command prompter cmd. But it won't run because it cannot import the win32com.client. When prompting or running my program...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.