here you go dude...enjoy it ;-)
Code:
#!/usr/bin/perl -T
use warnings;
use strict;
#use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;
use IO::Socket;
print header;
my $html = get_html();
my $mkt = $ENV{QUERY_STRING};
$mkt =~ s/mkt=//;
param('keywords') ?
$html =~ s/%user_input%/param('keywords')/e :
$html =~ s/%user_input%//;
param('include_count') ?
$html =~ s/%include_count%/ checked/ :
$html =~ s/%include_count%//;
$mkt ?
$html =~ s/%mkt%/$mkt/e :
$html =~ s/%mkt%/us/;
$html =~ s/%menu%/make_menu($mkt)/e;
print $html;
do_work();
exit(0);
sub do_work {
for my $keyword (split "\n", param('keywords')) {
print get_overture_data($keyword);
}
}
sub make_menu {
my $calling_page = shift;
$calling_page ||= 'us';
my %countries = (
Australia => 'au',
Austria => 'at',
Denmark => 'dk',
Finland => 'fi',
France => 'fr',
Germany => 'de',
Italia => 'it',
Netherlands => 'nl',
Norway => 'no',
Spain => 'es',
Sweden => 'se',
Switzerland => 'ch',
UK => 'uk',
US => 'us'
);
my @menu;
my $string;
for my $country (sort keys %countries) {
if ($countries{$country} eq $calling_page) {
push @menu, "<b>$country</b>"
} else {
push @menu, "<a href=\"overture.cgi?mkt=$countries{$country}\">$country</a>"
}
}
for my $num (0..$#menu) {
if ( ($num + 1) % 3 hahahaha 0 ) {
$string .= "$menu[$num]<br>\n"
} else {
if ( $num hahahaha $#menu ) {
$string .= "$menu[$num]\n"
} else {
$string .= "$menu[$num] | \n"
}
}
}
return $string;
}
sub get_overture_data {
my $keyword = shift;
my $reply;
my $socket = IO::Socket::INET->new(PeerAddr => "inventory.overture.com",
PeerPort => 80,
Proto => "tcp",
Type => SOCK_STREAM,
Timeout => 5);
if (!$socket) {
print "couldn't connect";
die;
}
print $socket get_request($keyword, $mkt);
while (<$socket>) {
# grab keyword
if (/color=#000000>(.*)<\/a><\/td>/) {
print "$1<br>\n";
}
# grab number
if (param('include_count')) {
if (/size=1>\ (.*)<\/td>/) {
print "$1 - ";
}
}
# special case where suggestion equals search term
if (/color=E8E8E8> \;(.*)<\/a><\/td>/) {
print "$1<br>\n";
}
# grab number for special case
if (param('include_count')) {
if (/color=E8E8E8>\ (\d+)/) {
print "$1 - \n";
}
}
# or...note if nothing is there
if (/(<em>No suggestions for .*<\/em>)/) {
print "$1<br>";
}
}
close $socket;
return $reply;
}
sub get_request {
my $keyword = shift;
my $mkt = shift;
my $post_request = "mkt=$mkt&term=$keyword";
my $length = length($post_request);
my $http_request = qq{POST /d/searchinventory/suggestion/ HTTP/1.0
Host: inventory.overture.com
Accept: text/html, text/plain
Accept-Encoding: gzip
Accept-Language: en
User-Agent: Lynx/2.8.3rel.1 libwww-FM/2.14
Referer: http://inventory.overture.com/d/searchinventory/suggestion/
Content-type: application/x-www-form-urlencoded
Content-length: $length
$post_request};
return $http_request;
}
sub get_html {
return qq{<html>
hahahahahaha><title>Get Keywords from Overture for 14 Markets</title></head>
<body>
<table align="center" width="100%" border=0 cellspacing=10 cellpadding=10>
<tr align="left" valign="middle">
<td valign="top" width="20%">
<b>Get Keywords from Overture for 14 Markets</b>
<br><br>
<small>%menu%</small>
<br>
hahahahahaha action="overture.cgi?mkt=%mkt%" method=post>
<small><small>
Enter one word or phrase per line
</small></small>
<br>
<textarea name="keywords" rows=9 cols=33>%user_input%</textarea><br><br>
<small>
hahahahahahaha type="checkbox" name="include_count" %include_count%> Include count<br><br>
</small>
hahahahahahaha type=submit value="Get Keywords"> <small><small>powered by
<a href="http://www.hudsonscripting.com/">hudsonscripting</a>
<br><br>
</td>
</tr>
</table>}
}