WWW::Mechanizeが便利

この記事は2年以上前に書いたものです。
そのため情報が古い可能性があります。ご了承ください。m(_ _)m

WWW::Mechanize – search.cpan.org

WWW::Mechanize, or Mch for short, is a module for stateful programmatic web browsing, used for automating interaction with websites.

Features include:

  • All HTTP methods
  • High-level hyperlink and HTML form support, without having to parse HTML yourself
  • support
  • Automatic cookies
  • Custom HTTP headers
  • Automatic handling of redirections
  • Proxies
  • HTTP authentication

Mech supports performing a sequence of page fetches including following links and submitting forms. Each fetched page is parsed and its links and forms are extracted. A link or a form can be selected, form fields can be filled and the next page can be fetched. Mech also stores a history of the URLs you've visited, which can be queried and revisited.

websiteとの対話を自動化するモジュール。

RSSフィード配信サービスを利用していると手動で指定先へ送信するのは無料だけど、定期的に指定先へ送信するのは有料みたいなのがよくある。(例えば、kindlefeeder.comとか)
そういうサービスも、Mechanize使ってスクリプト書いて、cronで回せば無料で定期的に送信可能。

kindlefeeder.comだと

#!/usr/bin/perl

use WWW::Mechanize;

my $mech = new WWW::Mechanize( autocheck => 1, agent => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)' );

$mech->get('http://kindlefeeder.com/users/xxxxx');

# login
$mech->submit_form(
    fields => {
        login => 'username',
        password => 'passwd',
    },
    );

# submit
my $response = $mech->submit_form(
    form_number => 2,
    );

みたいな感じで。まぁ、ページの内容が変わると、その都度対応必要だけど。

カテゴリー: プログラム タグ: , , , , , , パーマリンク

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です