うまいぼうぶろぐ

linuxとhttpdとperlのメモ

perlでmixiボイスにpostする

今さらだけどWeb::Scraperとかの勉強がてらに書いてみた。

#!/usr/bin/perl
use strict;
use warnings;

use WWW::Mixi;
use Web::Scraper;
use Encode;
use File::Basename;

my $mixi = WWW::Mixi->new('username', 'password');
$mixi->login;
my $res = $mixi->get('recent_voice.pl');

my $scraper = scraper {
  process '#voicePost input.#post_key', 'post_key' => '@value';
  process '#voicePost input.#redirect', 'redirect' => '@value';
  process '#voicePost input.#defaultValue', 'default_value' => '@value';
};
my $result = $scraper->scrape( $res->content );

my $message = shift || 'ほげほげ'; $message .= " via " . basename $0;
my $decoded = decode('utf-8', $message);
my $encoded = encode('euc-jp', $decoded);

$result->{body} = $encoded;
$res = $mixi->post('add_voice.pl', $result);