Skip to content

Instantly share code, notes, and snippets.

@ntakanashi
Created June 19, 2013 02:32
Show Gist options
  • Save ntakanashi/5811276 to your computer and use it in GitHub Desktop.
Save ntakanashi/5811276 to your computer and use it in GitHub Desktop.
Get title from url.
#!/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