myfrndjk has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks I am here to seek a help from you .I have perl-cgi script ,when called it has to crawl the site and print the crawled data both in web page and as text/html file.If I use command prompt to execute the script it works fine, however if I execute through browser contents displayed only in web page not printed in external file.Thanks in advance
#!/usr/bin/perl use strict; use warnings; use HTML::TreeBuilder::XPath; use LWP::UserAgent ; use HTTP::Request ; open (OUT, '>:encoding(cp1252)',"/home/local/ANT/hemesh/Desktop/test.h +tml"); my $URL = 'http://www.7dayshop.com/delivery-and-returns'; my $agent = LWP::UserAgent->new(agent => "Mozilla/5.0"); my $request = HTTP::Request->new(GET=> $URL); my $response = $agent->request($request); # Check the outcome of the response if ($response->is_success) { my $xp = HTML::TreeBuilder::XPath->new_from_url($URL); my $node = $xp->findnodes_as_string('//strong[contains(.,\'UK Mainland + Standard\')]'); print "Content-type: text/html\n\n"; print OUT $node and print $node; } elsif ($response->is_error) { print "Error:$URL\n"; print $response->error_as_HTML; }
Expected result
Web page: my crawl data
test.html in desktop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: print result in text/html file-perl cgi
by graff (Chancellor) on Jul 27, 2014 at 20:49 UTC | |
by myfrndjk (Sexton) on Jul 31, 2014 at 00:40 UTC | |
|
Re: print result in text/html file-perl cgi
by 1s44c (Scribe) on Jul 27, 2014 at 21:03 UTC | |
|
Re: print result in text/html file-perl cgi
by Anonymous Monk on Jul 27, 2014 at 20:51 UTC | |
|
Re: print result in text/html file-perl cgi
by Anonymous Monk on Jul 27, 2014 at 22:32 UTC | |
by myfrndjk (Sexton) on Jul 31, 2014 at 00:39 UTC |