WWW::Mechanizeにページ解析ツールが付いてた

フォームの内容を調べる時にFirefox拡張のWeb Developerなどを頼りに調べていたのだけども、基本的にコマンドライン派なので少々( ゚Д゚)マンドクセーと思っていた。で、WWW::Mechanizeにmech-dumpというツールが付いていたので使ってみたら、これがほんとすごく便利。

使い方は簡単で、URIを渡すだけでフォームを解析した結果を表示してくれる。

$ mech-dump "http://google.com"
GET http://www.google.co.jp/search [f]
  hl=ja                          (hidden readonly)
  ie=Shift_JIS                   (hidden readonly)
  q=                             (text)
  btnG=Google 検索               (submit)
  btnI=I'm Feeling Lucky         (submit)
  lr=                            (radio)    [*|lang_ja]

オプションによって、そのページに含まれるリンク一覧や画像一覧も抽出できる。

$ mech-dump --help
Usage:
    mech-dump [options] [file|url]

    Options:

        --forms         Dump table of forms (default action)
        --links         Dump table of links
        --images        Dump table of images
        --all           Dump all three of the above, in that order

        --absolute      Show URLs as absolute, even if relative in the page
        --help          Show this message

    The order of the options specified is relevant. Repeated options get
    repeated dumps.

ktkr!