serpretetsky
2[H]4U
- Joined
- Dec 24, 2008
- Messages
- 2,180
I'm trying to use perl and LWP::Simple to make a small script that gets the html code for a google search. Currently I just have it print out the code and URL it used to get the code in the "returnHtml" subroutine.
The problem is that LWP::Simple is only working on just the domain name, not the whole URL. Is this the way it's supposed to work or did I brake it somehow?
for example, with the current huge mess of URL in there, LWP::Simple "get" gives me nothing, blank. ----edit: (it doesn't trip my " != defined" error-catch either).
However, if I replace that giant URL with something like "http://www.google.com" or "http://www.yahoo.com" it prints out the HTML code right away.
What am I doing wrong?
Thank you for any help.
The problem is that LWP::Simple is only working on just the domain name, not the whole URL. Is this the way it's supposed to work or did I brake it somehow?
for example, with the current huge mess of URL in there, LWP::Simple "get" gives me nothing, blank. ----edit: (it doesn't trip my " != defined" error-catch either).
However, if I replace that giant URL with something like "http://www.google.com" or "http://www.yahoo.com" it prints out the HTML code right away.
What am I doing wrong?
Thank you for any help.
Code:
#!/usr/bin/perl
use strict;
use LWP::Simple;
my $urlSearch = convertSrchToUrl($ARGV[0]);
my $htmlUnfiltered = returnHtml($urlSearch);
sub returnHtml {
my $content = get $_[0];
if ($content != defined){
die "Could not recieve html data for given url: $urlSearch";
}
print $_[0];
print $content;
return($content);
}
sub convertSrchToUrl {
my $url = "http://www.google.com/#hl=en&output=search&sclient=psy-ab&q=" . $_[0] . "&pbx=1&oq=" . $_[0] . "&aq=f&aqi=g-m1&aql=&gs_sm=3&gs_upl=709l3851l0l4189l6l6l0l0l0l0l99l478l6l6l0&bav=on.2,or.r_gc.r_pw.r_qf.,cf.osb&fp=569c85e601367506&biw=665&bih=607";
return($url);
}