Created
June 19, 2013 02:32
-
-
Save ntakanashi/5811276 to your computer and use it in GitHub Desktop.
Get title from url.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use common::sense; | |
use Furl::HTTP; | |
use HTML::TagParser; | |
$ARGV[0] =~ /(s?https?:\/\/[-_.!~*'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)/ or die 'invalid format'; | |
my $url = $1; | |
my $furl = Furl::HTTP->new; | |
my ($minor_version, $status, $message, $headers, $content) = $furl->request( | |
method => 'GET', | |
url => $url, | |
); | |
die "$status: $message" unless substr( $status, 0, 1 ) eq 2; | |
my $parser = HTML::TagParser->new($content); | |
my $title = $parser->getElementsByTagName('title')->innerText(); | |
say $title; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment