Open HTML file in IE

Discussion in 'Python' started by gravey, Jul 18, 2007.

  1. gravey

    gravey Guest

    Hello.

    Apologies if this is a basic question, but I want to open a HTML
    file from my local drive (is generated by another Python script)
    in Internet Explorer. I've had a look at the webbrowser module and
    this doesn't seem to be what I need. Any help much appreciated.
     
    gravey, Jul 18, 2007
    #1
    1. Advertising

  2. gravey

    Larry Bates Guest

    gravey wrote:
    > Hello.
    >
    > Apologies if this is a basic question, but I want to open a HTML
    > file from my local drive (is generated by another Python script)
    > in Internet Explorer. I've had a look at the webbrowser module and
    > this doesn't seem to be what I need. Any help much appreciated.
    >


    There are several ways. Assuming that IE is your default browser, just do:

    import os
    os.system('filename.html')

    If you want to make certain that IE is launched (and not FireForx or some other
    defult broswer) you can do:

    os.system("start iexplore filename.html")

    (at least this works on my system).

    -Larry
     
    Larry Bates, Jul 18, 2007
    #2
    1. Advertising

  3. gravey

    brad Guest

    gravey wrote:
    > Hello.
    >
    > Apologies if this is a basic question, but I want to open a HTML
    > file from my local drive (is generated by another Python script)
    > in Internet Explorer. I've had a look at the webbrowser module and
    > this doesn't seem to be what I need. Any help much appreciated.


    You may try something like this example:

    import time
    import win32com.client

    wie = win32com.client.Dispatch('InternetExplorer.Application')

    # Make IE Window Visible.
    wie.Visible = 1

    # Open this URL
    wie.Navigate('www.your_url.com')

    # Print 'Busy' while Busy.
    while wie.Busy:
    print 'Busy'

    # Sleep 2 secs, then go home.
    time.sleep(2)
    wie.GoHome()

    # Sleep 2 secs, then go back.
    time.sleep(2)
    wie.GoBack()

    # Refresh the page
    time.sleep(2)
    wie.Refresh()

    # Close IE Window
    time.sleep(2)
    wie.Quit()
     
    brad, Jul 18, 2007
    #3
  4. gravey

    imageguy Guest

    On Jul 18, 3:20 am, gravey <> wrote:
    > Hello.
    >
    > Apologies if this is a basic question, but I want to open a HTML
    > file from my local drive (is generated by another Python script)
    > in Internet Explorer. I've had a look at the webbrowser module and
    > this doesn't seem to be what I need. Any help much appreciated.


    check out the os module.
    os.startfile("your_htmlfile.html") should do it.
     
    imageguy, Jul 19, 2007
    #4
  5. gravey

    gravey Guest

    On Jul 19, 5:59 am, brad <> wrote:
    > gravey wrote:
    > > Hello.

    >
    > > Apologies if this is a basic question, but I want to open a HTML
    > > file from my local drive (is generated by another Python script)
    > > in Internet Explorer. I've had a look at the webbrowser module and
    > > this doesn't seem to be what I need. Any help much appreciated.

    >
    > You may try something like this example:
    >
    > import time
    > import win32com.client
    >
    > wie = win32com.client.Dispatch('InternetExplorer.Application')
    >
    > # Make IE Window Visible.
    > wie.Visible = 1
    >
    > # Open this URL
    > wie.Navigate('www.your_url.com')
    >
    > # Print 'Busy' while Busy.
    > while wie.Busy:
    > print 'Busy'
    >
    > # Sleep 2 secs, then go home.
    > time.sleep(2)
    > wie.GoHome()
    >
    > # Sleep 2 secs, then go back.
    > time.sleep(2)
    > wie.GoBack()
    >
    > # Refresh the page
    > time.sleep(2)
    > wie.Refresh()
    >
    > # Close IE Window
    > time.sleep(2)
    > wie.Quit()


    Thanks to all who replied. All your approaches work but (!!) the HTML
    page that I want to open contains Javascript that parses some
    parameters
    from the URL. The URL looks like this:

    file:///C|/Temp/Google%20Maps/linktothis.htm?lat=45.0&lng=-20.0&zoom=4&type=k

    The Javascript gets the URL from the Javascript location object and
    parses it. I'm assuming that the location object has some kind of
    Windows equivalent that might be set using win32com.client. Can anyone
    shed any light on this?

    Thanks
     
    gravey, Jul 20, 2007
    #5
  6. gravey

    7stud Guest

    On Jul 19, 11:09 pm, gravey <> wrote:
    > The URL looks like this:
    >
    > file:///C|/Temp/Google%20Maps/linktothis.htm?lat=45.0&lng=-20.0&zoom=4&type =k
    >
    > The Javascript gets the URL from the Javascript location object and
    > parses it. I'm assuming that the location object has some kind of
    > Windows equivalent that might be set using win32com.client. Can anyone
    > shed any light on this?
    >
    > Thanks


    The location object is just your url. So, if the url of the page you
    open in IE is parsed by javascript, then you need to use a url with
    the proper information in it.
     
    7stud, Jul 20, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. THY
    Replies:
    4
    Views:
    517
    Gönen EREN
    Aug 22, 2003
  2. Schüle Daniel

    File::open and File.open

    Schüle Daniel, Oct 23, 2006, in forum: Ruby
    Replies:
    4
    Views:
    192
    Rick DeNatale
    Oct 24, 2006
  3. Scott Elwood

    File.open of HTML file removes code

    Scott Elwood, Apr 27, 2011, in forum: Ruby
    Replies:
    5
    Views:
    132
    Scott Elwood
    Apr 28, 2011
  4. Lucy
    Replies:
    6
    Views:
    348
    Jim Ley
    Jan 1, 2004
  5. Matt
    Replies:
    1
    Views:
    473
    Michael Winter
    Aug 22, 2004
Loading...

Share This Page