D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Website automation

 

Oh for the record I kind of took Phil's advice, and used MozRepl but
with the Perl bindings. Mostly because I wanted to apply weird regexp to
output (but to be honest "grep" and "sed" would have been as easy)

It isn't elegant but it does the job.

So something like this:

#!/usr/bin/perl -w
use strict;
use WWW::Mechanize::Firefox;

my $mech = WWW::Mechanize::Firefox->new(
    activate => 1, # bring the tab to the foreground
    autodie => 0, # Don't die on errors
    synchronize => 0
);

$mech->autodie(0);

$mech->get('http://www.example.com/');

if (! $mech->success()) {

### and so on ###

Wrapped in a script that fires up Firefox in xvfb-run, so it can run
headless.

xvfb-run iceweasel 1>/dev/null 2>/dev/null &
sleep 5
Mechanize-Test1.pl


Could do with more error checking, and some more sophisticated bits, but
it is run by cron which filters the normal output, so I get an email if
it doesn't succeed.

-- 
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq