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


In reply to print result in text/html file-perl cgi by myfrndjk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.