Another MSIE Python Question

R

Ralph A. Gable

I am opening MSIE6 with this code:

ie=Dispatch('InternetExplorer.Application.1')
ie.Navigate(url)
while ie.Busy:
time.sleep(0.1)
ied=ie.Document
while ied.ReadyState != 'complete':
time.sleep(0.1)

ieh=ied.documentElement.outerHTML


When opening Word or Excel, and using Dispatch('Word.Application') or
Dispatch('Excel.Application'), the app comes up and is available and can be
brought up on the screen by setting .Visible = 1. When using the above code,
IE will not come up. I have to open IE by clicking on its icon and then the
above code will work. If I don't do that I get a stack dump and my python
program crashes.

Any help would be appreciated.
 
P

Peter Hansen

Ralph said:
I am opening MSIE6 with this code:

ie=Dispatch('InternetExplorer.Application.1')
ie.Navigate(url)
while ie.Busy:
time.sleep(0.1)
ied=ie.Document
while ied.ReadyState != 'complete':
time.sleep(0.1)

ieh=ied.documentElement.outerHTML


When opening Word or Excel, and using Dispatch('Word.Application') or
Dispatch('Excel.Application'), the app comes up and is available and can be
brought up on the screen by setting .Visible = 1. When using the above code,
IE will not come up. I have to open IE by clicking on its icon and then the
above code will work. If I don't do that I get a stack dump and my python
program crashes.

Any help would be appreciated.

Based on the above description, is it possible that the fact
that you aren't doing "ie.Visible = 1" is responsible?

Also, please include the traceback when saying that your Python program
crashes... this usually eliminates whole classes of possible causes,
and often points directly to the trouble for someone who's been there
before.

-Peter
 
M

Michael Geary

Ralph said:
I am opening MSIE6 with this code:

ie=Dispatch('InternetExplorer.Application.1')
ie.Navigate(url)
while ie.Busy:
time.sleep(0.1)
ied=ie.Document
while ied.ReadyState != 'complete':
time.sleep(0.1)

ieh=ied.documentElement.outerHTML


When opening Word or Excel, and using Dispatch('Word.Application') or
Dispatch('Excel.Application'), the app comes up and is available and can be
brought up on the screen by setting .Visible = 1. When using the above code,
IE will not come up. I have to open IE by clicking on its icon and then the
above code will work. If I don't do that I get a stack dump and my python
program crashes.

My working code is similar to yours, but I use
'InternetExplorer.Application' instead of 'InternetExplorer.Application.1'
in the Dispatch call. I wonder if that could make the difference.

-Mike
 
R

Ralph A. Gable

Here's the stack dump:
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python22\lib\ufutil.py", line 661, in updatetocurrent
getplayerdata(l,i)
File "C:\Python22\lib\ufutil.py", line 478, in getplayerdata
ie=Dispatch('InternetExplorer.Application.1')
File "C:\Python22\lib\site-packages\win32com\client\__init__.py",
line 95, in Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python22\lib\site-packages\win32com\client\dynamic.py",
line 84, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python22\lib\site-packages\win32com\client\dynamic.py",
line 72, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221231, 'ClassFactory cannot supply requested class',
None, None)
 
P

Peter Hansen

Ralph A. Gable wrote:

[traceback snipped]

So what if you drop the '.1' from the end of the AppId, and
also make sure you have the "ie.Visible = 1" in there?

Can you upgrade to the latest versions of Python and pywin32
as well? I notice you are using 2.2 still...

(No idea if any of these things will help... I'm spending a
lot of time struggling with COM right now as well, though
with troubles in entirely different areas.)

-Peter
 
R

Ralph A. Gable

I have dropped the .1. I don't even get to the point where I CAN set
..Visible=1 since it crashes before it brings up msie.

I guess I wasn't clear enough in the original message. What I want to
do is be able to bring up an instance of msie (and NOT make if
visible) that python can use and that will not be seen by the user,
i.e. I want all the operations I am performing with msie to be hidden
from the user so said user can go about his/her business and never
know anything is going on. In the case of Word/Excel I can do that
with no problem. I just don't set .Visible to 1 but when trying to use
msie (with python) I can't do it unless I already have an instance of
msie running BEFORE I run the code cited below.
 
K

Konstantin Veretennicov

I am opening MSIE6 with this code:

ie=Dispatch('InternetExplorer.Application.1')
ie.Navigate(url)
while ie.Busy:
time.sleep(0.1)
ied=ie.Document
while ied.ReadyState != 'complete':
time.sleep(0.1)

ieh=ied.documentElement.outerHTML


I have tried your code as is (added imports, of course) and it worked.
IE didn't show up in taskbar, url was loaded and outerHTML contained,
well, HTML :)

Test environment: Win2k, MSIE 6 and ActivePython 2.3.

- kv
 

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,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top