Skip to content

Instantly share code, notes, and snippets.

@sharl
Created January 23, 2013 04:06
Show Gist options
  • Save sharl/4601828 to your computer and use it in GitHub Desktop.
Save sharl/4601828 to your computer and use it in GitHub Desktop.
Google Feeling Lucky
#!/usr/bin/env perl
use strict;
use warnings;
use URI::Escape 'uri_escape';
use LWP::Simple qw(head $ua);
if ($ARGV[0]) {
my $word = join('', @ARGV);
my $URI = 'https://www.google.com/search?q=' . uri_escape($word) . '&btnI';
$ua->agent('Monazilla/1.00 (compatible;)');
$ua->timeout(10);
my $res = head($URI);
if ($res && $res->previous) {
my $location = $res->previous->header('Location');
print "$word $location\n";
exit;
}
print "no match $word\n";
}
@sharl
Copy link
Author

sharl commented Jan 23, 2013

$ gfl ふわふわうさこ
ふわふわうさこ http://ja.wikipedia.org/wiki/%E3%83%8A%E3%82%A4%E3%83%B3%E3%83%81%E3%82%A7%E3%83%BB%E3%83%97%E3%83%A9%E3%82%A6%E3%82%B9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment