Development

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • separate IE instances?

    12 answers - 592 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    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 IEXPLRE 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
  • No.1 | | 1056 bytes | |

    "Chris Curvey" <ccurvey (AT) gmail (DOT) comwrote in message
    news:1118102755.309346.169810@
    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 IEXPLRE 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.Application", None,\
    pythoncom.CLSCTX_SERVER,
    pythoncom.IID_IDispatch)
    ie1 = Dispatch(ie1)
    ie2 = pythoncom.CoCreateInstance("InternetExplorer.Application", None,\
    pythoncom.CLSCTX_SERVER,
    pythoncom.IID_IDispatch)
    ie2 = Dispatch(ie2)
  • No.2 | | 149 bytes | |

    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.
  • No.3 | | 518 bytes | |

    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 S's that doesn't
    allow you to have two instances of IEXPRE.EXE running IW the S 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
  • No.4 | | 336 bytes | |

    I would have given up on this a long time ago, but I can create two
    IEXPLRE processes simultaneously (and get the behavior I want) by just
    manually launching them from the Start menu. ( course, that doesn't
    mean that I can launch them programmatically, but I'm hoping that
    someone can give me a definitive answer.)
  • No.5 | | 991 bytes | |

    "Chris Curvey" <ccurvey (AT) gmail (DOT) comwrote in message
    news:1118165668.863841.291290@
    I would have given up on this a long time ago, but I can create two
    IEXPLRE processes simultaneously (and get the behavior I want) by just
    manually launching them from the Start menu. ( 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 CM 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
  • No.6 | | 1932 bytes | |

    "Chris Curvey" <ccurvey (AT) gmail (DOT) comwrote in message
    news:1118165668.863841.291290@
    I would have given up on this a long time ago, but I can create two
    IEXPLRE processes simultaneously (and get the behavior I want) by just
    manually launching them from the Start menu. ( 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" <correiajREMVECAPS (AT) hotmail (DOT) comwrote 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 CM 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,None,1)
    b = win32api.ShellExecute(0,None,"iexplore.exe",None,None,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:

    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
  • No.7 | | 746 bytes | |

    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.
  • No.8 | | 1070 bytes | |

    >Chris Curvey" <ccurvey (AT) gmail (DOT) comwrote in message
    news:1118191737.550326.267750@
    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 CM, 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.
  • No.9 | | 317 bytes | |

    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,None,1)
    internetExplorerClassIdentity='{}'
    hwnds = Dispatch(internetExplorerClassIdentity)
    = hwnds[1]
    Navigate("")
  • No.10 | | 610 bytes | |

    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 " = 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.
  • No.11 | | 1144 bytes | |

    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='{}'
    hwnds = Dispatch(internetExplorerClassIdentity)
    # way I showed you before dosn't work verry well if more then one ie is
    open
    # = hwnds[0]
    #Navigate("")
    time.sleep(30)
    for i in range(hwnds.Count):
    if hwnds[i].LocationURL.lower().find("ishpeck") -1:
    = hwnds[i]
    if hwnds[i].LocationURL.lower().find("google") -1:
    = hwnds[i]

    Navigate("")
    Navigate("#343672a01d5b2cdc")
  • No.12 | | 1899 bytes | |

    <erinhouston (AT) gmail (DOT) comwrote in message
    news:1118671935.537464.150380@
    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='{}'
    hwnds = Dispatch(internetExplorerClassIdentity)
    # way I showed you before dosn't work verry well if more then one ie is
    open
    # = hwnds[0]
    #Navigate("")
    time.sleep(30)
    for i in range(hwnds.Count):
    if hwnds[i].LocationURL.lower().find("ishpeck") -1:
    = hwnds[i]
    if hwnds[i].LocationURL.lower().find("google") -1:
    = hwnds[i]

    Navigate("")

    Navigate("
    #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

Re: separate IE instances?


max 4000 letters.
Your nickname that display:
In order to stop the spam: 8 + 7 =
QUESTION ON "Development"

EMSDN.COM