I discovered and installed a firefox addon called Remote Control. This addon starts a telnet server which lets you send javascript commands to the firefox web browser. Combined with python telnetlib module, it becomes very easy to reload or change the content of a tab in a running firefox from a python script. Note that the addon manages only one tab at a time.
Load, reload a firefox tab from python.
#!/usr/bin/env python
# -*-coding: utf8-*-
# Title: remotecontrol.py
# Author: Gribouillis
# Created: 2012-02-03 14:51:45.755655 (isoformat date)
# License: Public Domain
# Use this code freely.
""" This module allows to change or reload the content of a tab in
a running firefox instance equiped with the Remote Control addon
(see https://addons.mozilla.org/en-US/firefox/addon/remote-control)
Notice that after installing the addon, you must install a
Remote Control icon in firefox add-on bar for this to work
(right click in the menubar and choose Customize).
See the example in the __main__ section below.
"""
import sys
import telnetlib
version_info = (0, 1)
version = ".".join(map(str, version_info))
class Control(object):
def __init__(self, port=32000):
self.host = 'localhost'
self.port = port
def reload(self):
tn = telnetlib.Telnet(self.host, self.port)
tn.write("reload\n")
result = tn.read_until('\n')
return result
def load(self, url):
tn = telnetlib.Telnet(self.host, self.port)
tn.write('window.location="%s"' % url)
result = tn.read_until('\n')
return result
if __name__ == "__main__":
"This part will run after selecting a tab for remote control in firefox"
from time import sleep
c = Control()
print c.load("http://www.python.org")
sleep(1)
print c.reload()
sleep(1)
print c.load("http://www.daniweb.com")
Gribouillis 1,391 Programming Explorer Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.