So I'm running a localhost test server with Windows 7 and Xampp. I'm working on a web crawler that will crawl the web, but when I open it up in my browser I get the Premature end of script headers error. I thought I got this from not including "print "Content-Type: text/html\n\n";" which is generally the issue.. but it wasn't.
This is the code I'm using:
#!"\xampp\perl\bin\perl.exe"
print "Content-Type: text/html\n\n";
use strict;
use warnings;
use LWP::Simple;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use HTML::LinkExtor;
open my $file1,"+>>", ("links.txt");
select($file1);
my @urls = ('http://www.youtube.com/');
my $browser = LWP::UserAgent->new('IE 6');
$browser->timeout(10);
while (@urls) {
my $url = shift @urls;
my $request = HTTP::Request->new(GET => $URL);
my $response = $browser->request($request);
if ($response->is_error()) {printf "%s\n", $response->status_line;}
my $contents = $response->content();
my ($page_parser) = HTML::LinkExtor->new(undef, $url);
$page_parser->parse($contents)->eof;
@links = $page_parser->links;
foreach $link (@links) {
push @urls, $$link[2]; # Add link to list of urls before printing it
print "$$link[2]\n";
}
sleep 60;
}