例えばWebで蔵書検索を行う館で元々ISBN検索出来る機能をフォームを変更することで検索機能を殺している場合に無理矢理Mechで送信すると $mech->select('code_genre1', '2'); $mech->submit_form( fields => { 'code_value1' => $isbn, } ); 当然の事ながらエラーになる Input "code_genre1" not found at ff.pl line 76 No such field 'code_value1' at /usr/local/lib/perl5/site_perl/5.8.8/WWW/Mechanize.pm line 1371 フォームにない項目をセットするとエラーになるという事は、フォームにある項目ならOK 同じパッケージでISBN検索機能がある館にmechをかけてDumpすれば
Perl CGI プログラムのテストには WWW::Mechanize::CGI を CGI プログラムを書いていて、いつも困るのがリグレッションテスト。 パッケージのビルド時に実行するテストスーツ (make check / make test 用テストプログラム群) に含めておきたいが、さすがにその場で Web サーバの下へセットアップするわけにもいかない。 ミニ Web サーバを同梱してテストスーツ内で起動する方法はちょっとおおがかかりだし、ポート番号の選択やらサーバの停止の問題もあって、かなり面倒。 結局、テストスーツの中で環境変数や標準入力など CGI リクエスト環境をセットアップして、CGI プログラムを実行するという王道(?)かつ泥臭いテストを書くことになったりする。 何かいいものはないかと探していたところ、WWW::Mechanize::CGI というものをみつけた。 LW
前記事 ウェブ自動巡回ボット-bot-の作り方 for Perl 初級編 - 後ろを見ろ、後ろを! 初級編はActivePerlと基本的なLWP:Simpleの使い方だけなので、そんなん知っとるわヴォケ-って人は飛ばしてもらって結構。引き続き一般的なWindowXP環境を想定して書きます。 スパムブログとは? アフィリエイト目的で自分のサイトにアクセスを誘導するための、内容が全く無いブログのこと。ニュースのヘッドラインを箇条書きしただけのうっとおしいサイトが検索にひっかかる事があると思うが、それは「引用スパム」と呼ばれる種類のブログで、日本のスパムブログの大半を占めているようだ。 日本のブログのなんと約40%がスパムブログであることが判明 - GIGAZINE http:/gigazine.net/index.php?/news/comments/20080326_spam_blog/
NAME VERSION SYNOPSIS 重要なリンク コンストラクタと開始 new() $mech->agent_alias( $alias ) known_agent_aliases() ページ取得メソッド $mech->get($url) $mech->reload() $mech->back() リンク追跡メソッド $mech->follow_link(...) フォームフィールド入力メソッド $mech->form_number($number) $mech->form_name($name) $mech->field( $name, $value, $number ) $mech->field( $name, \@values, $number ) $mech->set_fields( $name => $value ... ) $me
AutoPagerizeのSITEINFOに含まれている、次のページへのリンクを示すXPathはAutoPagerize以外の用途でも使うことができます。 CPANにこのSITEINFOをパースすめたるの HTML::AutoPagerize - Utility to load AutoPagerize SITEINFO stuff というモジュールがあるのは知っていたのですが、ページのロードと次のページのURLの解決もやってくれる WWW::Mechanize::AutoPager - Automatic Pagination using AutoPagerize というモジュールがあるのはさっき知りました... このモジュールを使うと、MechanizeでロードしたページがAutoPagerizeのSITEINFOに記述されていれば、自動的にSITEINFOのnextLinkを参照して
WWW::Mechanizeは、LWP::UserAgentを継承しているので、 LWP::UserAgentと同じ方法でBasic or Digest認証が出来ます。 リクエスト発生からの処理の流れは、 LWP::UserAgent::get LWP::UserAgent::request LWP::Authen::[Basic|Digest]::authenticate LWP::UserAgent::get_basic_credentials perldoc LWP::UserAgentを読むと、Basic/Digest認証を使うには サブクラスを作成しget_basic_credentials をオーバーライドするか、 credentials メソッドでパスワードを設定する。と書かれている。 credentials メソッドのほうが簡単そうなのでそちらを見てみる。 $ua->cre
以下は、他サイトに掲載されている有用なWWW::Mechanize使用例です。 私自身、「Amazon アフィリエイトレポート」を見て、本当にこのWWW::Mechanizeを使おう、と思いました。 Amazon アフィリエイトレポート(blog.bulknews.net)。 WWW::Mechanize を使って bk1 の注文履歴を取得するスクリプト(www.asmate.net)。 mixiの足あとを取得するスクリプト(digit.que.ne.jp)。日記を投稿するスクリプトのアレンジです。 指定したカテゴリの、今日の一覧を取得。 「次のページ」も追いかけて処理します。 use strict; use WWW::Mechanize; my $url = 'http://headlines.yahoo.co.jp/hl'; my $cate_label = 'コンピュータ一覧'; m
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く