#!/usr/bin/perl use strict; use warnings; use LWP::UserAgent; my $url = shift @ARGV; my $ua = LWP::UserAgent->new(timeout => 5); my $res = $ua->head($url); my $lurl = $res->request->uri || ""; print "$lurl\n";
% ./getlongurl.pl http://bit.ly/1RmnUT http://www.google.co.jp/ % ./getlongurl.pl http://flic.kr/p/7P5JBR http://www.flickr.com/photos/yto/4470939735/ % ./getlongurl.pl http://tinyurl.com/ybbp6e3 http://twilog.org/yto % ./getlongurl.pl http://ow.ly/1rPmd http://d.hatena.ne.jp/i_ogi/20090506/watershed % ./getlongurl.pl http://youtu.be/VtPJRbtZuJU http://www.youtube.com/watch?v=VtPJRbtZuJU&feature=youtu.be % ./getlongurl.pl http://j.mp/bIfgGG http://taisyo.seesaa.net/article/144848049.html
#!/usr/bin/env perl use strict; use warnings; use LWP::UserAgent; my $ua = LWP::UserAgent->new(timeout => 5); while (<>) { chomp; my @c = split(/\t/, $_); my $url = $c[0]; my $res = $ua->head($url); my $lurl = $res->request->uri || ""; print "$url\t$lurl\n" if $lurl; }
% cat getlongurls-test.txt http://tinyurl.com/ybbp6e3 http://ow.ly/1rPmd http://j.mp/bIfgGG % ./getlongurls.pl getlongurls-test.txt http://tinyurl.com/ybbp6e3 http://twilog.org/yto http://ow.ly/1rPmd http://d.hatena.ne.jp/i_ogi/20090506/watershed http://j.mp/bIfgGG http://taisyo.seesaa.net/article/144848049.html
↓$res->{_request}->{_uri}
$res->request->uri
金曜の朝から首が痛くて大変。
文字通り首が回らない。