I'm looking for a way to programatically control a browser on a Mac (i.e. Firefox or Safari or Chrome/-ium or Opera, but not IE) using Python.
The actions I need include following links, checking if elements exist in a page, and submitting forms.
Which solution would you recommend?
Try mechanize, if you don't actually need a browser.
Example:
Might be a bit restrictive, but py-appscript may be the easiest way of controlling a Applescript'able browser from Python.
For more complex things, you can use the PyObjC to achieve pretty much anything - for example, webkit2png is a Python script which uses WebKit to load a page, and save an image of it. You need to have a decent understanding of Objective-C and Cocoa/etc to use it (as it just exposes ObjC objects to Python)
Screen-scaping may achieve what you want with much less complexity.
You can use
selenium
library for Python, here is a simple example (in form ofunittest
):Several Mac applications can be controlled via OSAScript (a.k.a. AppleScript), which can be sent via the
osascript
command. O'Reilly has an article on invokingosascript
from Python. I can't vouch for it doing exactly what you want, but it's a starting point.