Help me. How to open a new IE window?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • angel

    Help me. How to open a new IE window?

    Hi

    I want python(win32com ) to open a new IE window.
    Source is:
    /******/
    import win32com.client
    msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
    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






  • Dave Brueck

    #2
    Re: Help me. How to open a new IE window?

    angel wrote:[color=blue]
    > I want python(win32com ) to open a new IE window.
    > Source is:
    > /******/
    > import win32com.client
    > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
    > 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.[/color]

    I ran into that same problem. Try this:

    msie = win32com.client .DispatchEx('In ternetExplorer. Application.1')

    It seems to work for me.

    -Dave

    Comment

    • Sean Ross

      #3
      Re: Help me. How to open a new IE window?


      "angel" <dai4happy@yaho o.com> wrote in message
      news:c7iaqu$240 0$1@news.f.de.p lusline.net...[color=blue]
      > Hi
      >
      > I want python(win32com ) to open a new IE window.
      > Source is:
      > /******/
      > import win32com.client
      > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
      > 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
      >[/color]


      Hi. Perhaps you may want to check out the webbrowser module:
      [color=blue][color=green][color=darkred]
      >>> import webbrowser as browser
      >>> browser.open("w ww.python.org", new=True)[/color][/color][/color]

      OR
      [color=blue][color=green][color=darkred]
      >>> browser.open_ne w(url)[/color][/color][/color]


      OR
      [color=blue][color=green][color=darkred]
      >>> IE = browser.Windows Default()
      >>> IE.open_new(url )[/color][/color][/color]


      HTH,
      Sean


      Comment

      • angel

        #4
        Re: Help me. How to open a new IE window?

        It's work. Thanx again!
        angel

        "Dave Brueck" <dave@pythonapo crypha.com>
        ??????:mailman. 355.1084020373. 25742.python-list@python.org ...[color=blue]
        > angel wrote:[color=green]
        > > I want python(win32com ) to open a new IE window.
        > > Source is:
        > > /******/
        > > import win32com.client
        > > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
        > > 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.[/color]
        >
        > I ran into that same problem. Try this:
        >
        > msie = win32com.client .DispatchEx('In ternetExplorer. Application.1')
        >
        > It seems to work for me.
        >
        > -Dave
        >[/color]


        Comment

        • Vladimir Ivanov

          #5
          Re: Help me. How to open a new IE window?

          angel wrote:[color=blue]
          > Hi
          >
          > I want python(win32com ) to open a new IE window.
          > Source is:
          > /******/
          > import win32com.client
          > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
          > 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
          >
          >
          >
          >
          >
          >[/color]
          import webbrowser
          webbrowser.open _new("www.pytho n.org")

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


          Comment

          • Dave Brueck

            #6
            Re: Help me. How to open a new IE window?

            Vladimir wrote:[color=blue]
            > angel wrote:[color=green]
            > > I want python(win32com ) to open a new IE window.
            > > Source is:
            > > /******/
            > > import win32com.client
            > > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
            > > 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.[/color]
            >
            > import webbrowser
            > webbrowser.open _new("www.pytho n.org")
            >
            > it will work fine with IE (if IE is the default browser)[/color]

            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


            Comment

            • calfdog@yahoo.com

              #7
              Re: Help me. How to open a new IE window?

              "Dave Brueck" <dave@pythonapo crypha.com> wrote in message news:<mailman.3 66.1084046682.2 5742.python-list@python.org >...[color=blue]
              > Vladimir wrote:[color=green]
              > > angel wrote:[color=darkred]
              > > > I want python(win32com ) to open a new IE window.
              > > > Source is:
              > > > /******/
              > > > import win32com.client
              > > > msie = win32com.client .Dispatch("Inte rnetExplorer.Ap plication")
              > > > 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.[/color]
              > >
              > > import webbrowser
              > > webbrowser.open _new("www.pytho n.org")
              > >
              > > it will work fine with IE (if IE is the default browser)[/color]
              >
              > 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[/color]

              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.sourcefor ge.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.lin ks:
              if link is None: break # needed for browser bug

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


              # Here is what you need
              ie = DispatchEx('Int ernetExplorer.A pplication')
              ie.Visible = 1
              ie.Navigate ('www.python.or g')

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


              #later
              #RLM

              Comment

              Working...