Help me. How to open a new IE window?

A

angel

Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Application")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor
 
D

Dave Brueck

angel said:
I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Application")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

I ran into that same problem. Try this:

msie = win32com.client.DispatchEx('InternetExplorer.Application.1')

It seems to work for me.

-Dave
 
S

Sean Ross

angel said:
Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Application")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor


Hi. Perhaps you may want to check out the webbrowser module:


HTH,
Sean
 
A

angel

It's work. Thanx again!
angel

Dave Brueck said:
I ran into that same problem. Try this:

msie = win32com.client.DispatchEx('InternetExplorer.Application.1')

It seems to work for me.

-Dave
 
V

Vladimir Ivanov

angel said:
Hi

I want python(win32com) to open a new IE window.
Source is:
/******/
import win32com.client
msie = win32com.client.Dispatch("InternetExplorer.Application")
msie.Visible = 1
msie.Naviagte(http://www.python.org)
/******/
The problem is the program always grabs a existed IExplorer window or
Explorer window. It never opens a new window.

Please help me. Thanx
Victor
import webbrowser
webbrowser.open_new("www.python.org")

it will work fine with IE (if IE is the default browser)
 
D

Dave Brueck

Vladimir said:
import webbrowser
webbrowser.open_new("www.python.org")

it will work fine with IE (if IE is the default browser)

I guess the OP didn't specify, but the above won't work if you need to control
the browser from then on (which is what I assume he was trying to do by
obtaining an IDispatch pointer to it).

-Dave
 
C

calfdog

Dave Brueck said:
I guess the OP didn't specify, but the above won't work if you need to control
the browser from then on (which is what I assume he was trying to do by
obtaining an IDispatch pointer to it).

-Dave

Here is how you do it:

Here is a quick way to do it but it works!
If you want to learn more go to pamie.sourceforge.net
This has a class file that helps you automate I.E.

# DispatchEX allows you to open a new window

from win32com.client import DispatchEx

import time

def wait(ie): # very important!!! you have to wait for each page to load
"Given an IE object, wait until the object is ready for input."
while ie.Busy: time.sleep(0.1)

doc = ie.Document
while doc.ReadyState != 'complete': time.sleep(0.1)
return doc

def ClickLink(ie, mylink):
#hrefs = []
for link in ie.Document.links:
if link is None: break # needed for browser bug

if link.innerText == mylink:
link.Click()


# Here is what you need
ie = DispatchEx('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate ('www.python.org')

# Some extra
wait(ie)# Very Important!
ClickLink(ie,'Search')


#later
#RLM
 

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
474,434
Messages
2,571,690
Members
48,796
Latest member
Greg L.

Latest Threads

Top