WWW::Mechanizeモジュールの存在がなければperlを覚えようと思わなかったかもしれません。ネット上での定型作業を自動化するのに大変便利なモジュールです。
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $file = "/path/to/output.xml";
my $u = 'ユーザ名';
my $p = 'パスワード';
my $start = 'http://ロリポブログのアドレス/admin/';
my @follow = (
{ url_regex => qr/mode=setting$/ },
{ url_regex => qr/mode=setting_export$/ },
{ url_regex => qr/mode=xml$/ }
);
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->get($start);
$mech->submit_form(
with_fields => {
account_name => $u,
password => $p
}
);
foreach (@follow) {
$mech->follow_link(%$_);
}
open FILE, ">$file" or die "Cannot open $file";
print FILE $mech->content();
close FILE;
我が家では初代玄箱の中でcronのジョブとして定期的に実行されています。
コメントする