open URL in the current tab

Jabba Laci jabba.laci at gmail.com
Mon Dec 10 19:05:54 EST 2012


Hi,

> If this is for use on somebody else's system, *please don't*. My

This is for me. I have a simple GUI that produces some URL that I want
to open in the current tab. Since I want to verify several URLs, I
don't want to open dozens of new tabs.

Here is my working solution. It requires the MozRepl Firefox add-on
that I mentioned in the previous message.

Laszlo

===========================

import telnetlib

HOST = 'localhost'
PORT = 4242    # MozRepl default

def open_curr_tab(url):
    tn = telnetlib.Telnet(HOST, PORT)
    cmd = "content.location.href = '{url}'".format(url=url)
    tn.read_until("repl> ")
    tn.write(cmd + "\n")
    tn.write("repl.quit()\n")

#########################

if __name__ == "__main__":
    open_curr_tab('http://www.python.org')



More information about the Python-list mailing list