germanchars_to_strange_html_chars($query)
####
use strict;
use HTTP::Request::Common; # HTTP handling
use LWP::UserAgent; # HTTP handling
use crypt::ssleay;
my $query = 'börse';
my $www;
#doesn't work.
#sends $query = 'börse';
$www = google_keyword_suggestions_html_debug('de', 'de', $query);
open F, "> doesntwork.html" or die "Cannot open.";
print F $www->content,"\n";
close F;
#works -- keyword suggestions are retrieved
#sends $query = 'börse';
#keyword suggestions are retrieved, although the html is kind of warped looking.
$query = germanchars_to_strange_html_chars($query);
$www = google_keyword_suggestions_html_debug('de', 'de', $query);
open F, "> works.html" or die "Cannot open.";
print F $www->content,"\n";
close F;
# returns $www object containing html for a successful code, or an error code
sub google_keyword_suggestions_html_debug {
my $language = shift;
my $country = shift;
my $query = shift; #this could be a list, but leaving it as a single word. maybe change later.
my $action = POST
'https://adwords.google.com/select/KeywordSandbox',
[
'save' => "save",
'wizard_name' => "keywordsandbox_wizard",
'language' => $language,
'country' => $country,
'keywords' => $query,
];
my $ua = LWP::UserAgent->new;
$ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
$ua->timeout(30);
my $www = $ua->request( $action );
return $www;
}
# Takes a variable and spits it back out with the proper german characters
sub germanchars_to_strange_html_chars {
my $var = shift;
my %table = ( 'ß' => 'ß', 'ä' => 'ä', 'ö' => 'ö',
'Ä' => 'ä', 'Ö' => 'ö', 'Ü' => 'ü',
'ü' => 'ü');
while (my ($k,$v) = each %table) {
$var =~ s/$k/$v/g;
}
return $var;
}