wordpressに対して自動で記事を投稿するスクリプト。perlからMechanizeを使いWEBアクセスをエミュレートして書き込むやり方。何度か実行する機会があったのでここにメモ。
#! /usr/bin/perl
use FindBin qw($Bin);
use WWW::Mechanize;
use utf8;
$URI = 'http://your_wordpress_url/wp-admin/';
$agent = 'WWW::Mechanize'->new();
$agent->get("$URI");
$agent->submit_form(
form_name => 'loginform',
fields => {
log => 'YOUR ID',
pwd => 'YOUR PASSWORD',
},
);
eval {
$URI = $URI."post-new.php";
$agent->get("$URI");
$data = $agent->content;
$agent->submit_form(
form_name => 'post',
fields => {
'post_title' => 'post title',
'content' => 'post contents',
},
button => 'publish'
);
};
if ($@) {
print "err\n";
exit 1;
};
exit 0;
Script sample to posting to wordpress by perl and mechanize.
