470,614 Members | 1,429 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

separate IE instances?

I need to create a set of IE instances that have different sets of
session cookies. I thought that using the win32com.DispatchEx function
would do this, but it doesn't seem to. In other words

ie1 = win32com.DispatchEx("InternetExplorer.Application" )
ie2 = win32com.DispatchEx("InternetExplorer.Application" )

gives me two IE windows, but only one IEXPLORE process in Task Manager.
And if I login to a site that uses session cookies to track sessions
using ie1, when I move ie2 to the same site, ie2 is already logged in.

Any help appreciated.

-Chris

Jul 19 '05 #1
12 2457
"Chris Curvey" <cc*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I need to create a set of IE instances that have different sets of
session cookies. I thought that using the win32com.DispatchEx function
would do this, but it doesn't seem to. In other words

ie1 = win32com.DispatchEx("InternetExplorer.Application" )
ie2 = win32com.DispatchEx("InternetExplorer.Application" )

gives me two IE windows, but only one IEXPLORE process in Task Manager.
And if I login to a site that uses session cookies to track sessions
using ie1, when I move ie2 to the same site, ie2 is already logged in.

Any help appreciated.

-Chris


from win32com.client import Dispatch

ie1 = pythoncom.CoCreateInstance("InternetExplorer.Appli cation", None,\
pythoncom.CLSCTX_SERVER,
pythoncom.IID_IDispatch)
ie1 = Dispatch(ie1)
ie2 = pythoncom.CoCreateInstance("InternetExplorer.Appli cation", None,\
pythoncom.CLSCTX_SERVER,
pythoncom.IID_IDispatch)
ie2 = Dispatch(ie2)
..
..
..

Jul 19 '05 #2
Bummer. No change at all. (In fact, I can't even call Navigate()
without throwing an error). I'm on win2k, if that makes any difference.

Jul 19 '05 #3
Chris Curvey wrote:
Bummer. No change at all. (In fact, I can't even call Navigate()
without throwing an error). I'm on win2k, if that makes any difference.

I could be way off, but isn't windows one of those OS's that doesn't
allow you to have two instances of IEXPORE.EXE running IOW the OS is
preventing you from running two instances of this executable. Someone
with a lot more knowledge of windows internals will I'm sure come along
and correct me ;-)

Mart

Jul 19 '05 #4
I would have given up on this a long time ago, but I can create two
IEXPLORE processes simultaneously (and get the behavior I want) by just
manually launching them from the Start menu. (Of course, that doesn't
mean that I can launch them programmatically, but I'm hoping that
someone can give me a definitive answer.)

Jul 19 '05 #5
"Chris Curvey" <cc*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I would have given up on this a long time ago, but I can create two
IEXPLORE processes simultaneously (and get the behavior I want) by just
manually launching them from the Start menu. (Of course, that doesn't
mean that I can launch them programmatically, but I'm hoping that
someone can give me a definitive answer.)


Right, I hadn't quite understood your problem when I posted my reply. The code
posted does work and allow navigation, etc. but you do have the problem with it
sharing the same session cookies (I'm also on Win2k). And to answer Martin, you
can definitely create as many iexplore.exe instances as you like in Windows.

How to get Python to launch several instances with COM... not sure, although I'm
99% certain it is doable. I'll hunt around and see if I can find a solution
which I'll post back.

J
Jul 19 '05 #6
> "Chris Curvey" <cc*****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
I would have given up on this a long time ago, but I can create two
IEXPLORE processes simultaneously (and get the behavior I want) by just
manually launching them from the Start menu. (Of course, that doesn't
mean that I can launch them programmatically, but I'm hoping that
someone can give me a definitive answer.)

"J Correia" <co****************@hotmail.com> wrote in message
news:LYlpe.38956$HI.25521@edtnps84... Right, I hadn't quite understood your problem when I posted my reply. The code posted does work and allow navigation, etc. but you do have the problem with it sharing the same session cookies (I'm also on Win2k). And to answer Martin, you can definitely create as many iexplore.exe instances as you like in Windows.

How to get Python to launch several instances with COM... not sure, although I'm 99% certain it is doable. I'll hunt around and see if I can find a solution
which I'll post back.


A very quick and very, very dirty method which might work is to start up
the instances as follows:
import win32api
a = win32api.ShellExecute(0,None,"iexplore.exe",None,N one,1)
b = win32api.ShellExecute(0,None,"iexplore.exe",None,N one,1)
This creates the 2 instances of iexplore.exe in Windows you're looking for.

Then use code like this to attach to the already running instances:
http://aspn.activestate.com/ASPN/Coo.../Recipe/269345

Haven't tried it because I'm certain there's a much more elegant solution, but
depending on how quickly you need to get going it might be a possible short term
work around until someone posts the better way. Perhaps you can also post some
more info on what you're actually trying to achieve... make it easier for
someone to
help or even suggest alternatives.

JC

Jul 19 '05 #7
thanks for all the help. I'll give the ShellExecute() approach a try
in the morning.

The short version of what I'm trying to do is....

Have my website login to a 3rd party website on behalf of my customer,
fill out a form, and submit it. I'm just using CGI to keep things
simple, but overlapping requests from different customers are the
problem. The 3rd party site uses a lot of javascript, so mechanize
isn't going to work. I could use some kind of locking mechanism and
"single-thread" access to IE, but that won't scale. I guess the next
approach would be to queue the requests and have a pool of worker
processes (running as different users) process the requests and report
back.

Jul 19 '05 #8
>Chris Curvey" <cc*****@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
thanks for all the help. I'll give the ShellExecute() approach a try
in the morning.

The short version of what I'm trying to do is....

Have my website login to a 3rd party website on behalf of my customer,
fill out a form, and submit it. I'm just using CGI to keep things
simple, but overlapping requests from different customers are the
problem. The 3rd party site uses a lot of javascript, so mechanize
isn't going to work. I could use some kind of locking mechanism and
"single-thread" access to IE, but that won't scale. I guess the next
approach would be to queue the requests and have a pool of worker
processes (running as different users) process the requests and report
back.


You might have a specific reason for using COM, but if not, have you
considered using the python urllib or urllib2 modules instead?
It should overcome the session cookie / overlapping request issues i think.
Jul 19 '05 #9
Here is quick and dirty example of what jc talked about.

import win32api
from win32com.client import Dispatch

a = win32api.ShellExecute(0,None,"iexplore.exe",None,N one,1)
internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
hwnds = Dispatch(internetExplorerClassIdentity)
ieObj = hwnds[1]
ieObj.Navigate("http://www.google.com/search?hl=en&lr=&q=python")

Jul 19 '05 #10
the good news is that if run the ShellExecute bit twice, I get two
instances of explorer in Task Manager

The bad news is that the line "ioObj = hwnds[1]" tells me either "This
object does not support enumeration" (if I have not used makepy to
generate the classes) or "object has no attribute __getitem__" (if I
have used makepy)

looking at the hwnds itself, it appears to be a

"win32com.gen_py.Microsoft Internet Controls.IWebBrowser2 instance"

If I call hwnds.Navigate("http://www.google.com"), I don't get an
error, but I also don't see anything change in IE.

Jul 19 '05 #11
Sorry about that I had an instance of ie running in the background that
was version 0 didn't see the problem tell this morining when my
computer started to not work. it should be hwnds[1] should be
hwnds[0]. I woud enumerate them like in the code below.

If you have ie as your default browser you can use a
shellExecute(0,None,"some url here", None, None, 1)
To open directley to that page.

Here is a more complete script:
import win32api, time
from win32com.client import Dispatch
a = win32api.ShellExecute(0,None,"iexplore.exe",
"www.ishpeck.net",None,1)
b = win32api.ShellExecute(0,None,"iexplore.exe",
"www.google.com",None,1)
internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
hwnds = Dispatch(internetExplorerClassIdentity)
# way I showed you before dosn't work verry well if more then one ie is
open
#ieObj = hwnds[0]
#ieObj.Navigate("http://www.google.com/search?hl=en&lr=&q=python")
time.sleep(30)
for i in range(hwnds.Count):
.....if hwnds[i].LocationURL.lower().find("ishpeck") > -1:
.........ieObj1 = hwnds[i]
.....if hwnds[i].LocationURL.lower().find("google") > -1:
.........ieObj2 = hwnds[i]

ieObj1.Navigate("http://www.google.com/search?hl=en&lr=&q=python")
ieObj2.Navigate("http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/ba1395566452dba6/343672a01d5b2cdc?hl=en#343672a01d5b2cdc")

Jul 19 '05 #12
<er*********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Sorry about that I had an instance of ie running in the background that
was version 0 didn't see the problem tell this morining when my
computer started to not work. it should be hwnds[1] should be
hwnds[0]. I woud enumerate them like in the code below.

If you have ie as your default browser you can use a
shellExecute(0,None,"some url here", None, None, 1)
To open directley to that page.

Here is a more complete script:
import win32api, time
from win32com.client import Dispatch
a = win32api.ShellExecute(0,None,"iexplore.exe",
"www.ishpeck.net",None,1)
b = win32api.ShellExecute(0,None,"iexplore.exe",
"www.google.com",None,1)
internetExplorerClassIdentity='{9BA05972-F6A8-11CF-A442-00A0C90A8F39}'
hwnds = Dispatch(internetExplorerClassIdentity)
# way I showed you before dosn't work verry well if more then one ie is
open
#ieObj = hwnds[0]
#ieObj.Navigate("http://www.google.com/search?hl=en&lr=&q=python")
time.sleep(30)
for i in range(hwnds.Count):
....if hwnds[i].LocationURL.lower().find("ishpeck") > -1:
........ieObj1 = hwnds[i]
....if hwnds[i].LocationURL.lower().find("google") > -1:
........ieObj2 = hwnds[i]

ieObj1.Navigate("http://www.google.com/search?hl=en&lr=&q=python")

ieObj2.Navigate("http://groups-beta.google.com/group/comp.lang.python/browse_thr
ead/thread/ba1395566452dba6/343672a01d5b2cdc?hl=en#343672a01d5b2cdc")

The thing to note is that hwnds brings back a list of all Internet Explorer
objects running on your machine. This *includes* things that might
not be obvious at first, like a simple Windows Explorer window
(or windows) you have running (since it uses IE in the background).
Printing hwnds.LocationName and hwnds.LocationURL in a loop
will show you exactly what processes are using IE at the time you run it.
Given that the returned list will vary each time you run your program
you'll definitely have to iterate through each hwnds item and check
if it is the browser session you want as shown in the above code.

JC
Jul 19 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Michael Williams | last post: by
4 posts views Thread by Chad Myers | last post: by
2 posts views Thread by Ravikanth[MVP] | last post: by
3 posts views Thread by =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.