Memo plus Alpha

メモにプラスアルファを加えて価値ある情報に。

【Perl】ホームページの更新日時を取得する(html,pdfなど)

ホームページの更新日時取得する方法。

 

「更新が滞っているページ」や「最も古いページ」を調べたい場合、以下のPerlのコードで更新日時を取得できます。

(1) modifieddate.pl

  1. use LWP::Simple;
  2. use HTTP::Status;
  3. require LWP;
  4. require LWP::UserAgent;
  5.  
  6. $ua = new LWP::UserAgent;
  7. $ua->agent("LWP::GETHEAD");
  8. open(URLLIST, "< urllist.txt") or die("error :$!");
  9.  
  10. while (my $line = <URLLIST>){
  11. chomp($line);
  12. $url = $line;
  13. $request = new HTTP::Request HEAD => $url;
  14. $response = $ua->request($request);
  15.  
  16. print "$url\t";
  17. print $response->header('Last-Modified');
  18. print "\n";
  19.  
  20.  
  21. }
  22.  
  23. を参考に作成
  24.  

(2) urllist.txt

調べるURLはurllist.txtに1行ずつ書いておきます。スクリプトと同じフォルダにおいてください。

http:// hogehogehogehoge/xx.html

http:// hogehogehogehoge/yy.html

http:// hogehogehogehoge/zz.html

 

ウェブページからリンクを抽出するには以下のようなサイトが便利(リンク、抽出、で検索)。

http://t.mscl.jp/chk/

 

(3)実行

コマンドラインでmodifieddate.plのフォルダに移動し以下を実行。

perl modifeddate.pl > result.txt

(4)結果

result.txtはこんな感じになります。pdfなどでも取得できるようです。タブ区切りで生成されるのでエクセルなどで読み込んでください。

http:// hogehogehogehoge/zz.pdfThu, 15 Sep 2011 02:23:46 GMT

http:// hogehogehogehoge/zz.html Thu, 15 Sep 2011 02:23:46 GMT