remote control firefox with python

Hans-Peter Jansen hpj at urpla.net
Tue Nov 30 08:30:30 EST 2010


On Sunday 28 November 2010, 16:22:33 News123 wrote:
> Hi,
>
>
> I wondered whether there is a simpe way to
> 'remote' control fire fox with python.
>
>
> With remote controlling I mean:
> - enter a url in the title bar and click on it
> - create a new tab
> - enter another url click on it
> - save the html document of this page
> - Probably the most difficult one: emulate a click or 'right click'
> on a certain button or link of the current page.
> - other interesting things would be to be able to enter the master
> 	password from a script
> - to enable disable proxy settings while running.
>
> The reason why I want to stay within Firefox and not use any other
> 'mechanize' frame work is, that the pages I want to automate might
> contain a lot of javascript for the construction of the actual page.

If webkit based rendering in an option (since its javascript engine is 
respected by web developers nowadays..), you might want to check out  
PyQt, based on current versions of Qt. It provides very easy access to 
a full featured web browser engine without sacrificing low level 
details. All your requirements are provided easily (if you're able to 
grok the Qt documentation, e.g. ignore all C++ clutter, you're set).

I've transcoded all available QtWebKit examples to python lately, 
available here:

http://www.riverbankcomputing.com/pipermail/pyqt/2010-November/028614.html

The attachment is a tar.bz2 archive, btw.

Clicking is archived by:

        webelement.evaluateJavaScript(
            "var event = document.createEvent('MouseEvents');"
            "event.initEvent('click', true, true);"
            "this.dispatchEvent(event);"
            )

Cheers,
Pete



More information about the Python-list mailing list