in reply to Proper use of HTML::Form for exctracting

This is what I've done for the test , made it as simple as possible just to try the module : 1. Page with input
<!DOCTYPE html> <html> <head> <title>Title</title> </head> <body> <form name="MyForm" action="/cgi-bin/ex.cgi",method="post",id="f1"> <input type="text" name="textfield"> </form> </body> </html>
2. After clicking enter it should call ex.cgi:
#!/usr/bin/perl use strict; use warnings; use HTML::Extract; my $extractor=new HTML::Extract; print "Content-type: text/html\n\n"; print "<html><body>\n"; print"$extractor->gethtml('http://192.168.0.104/' ,tagname=body,return +type=text)<p1>"; print"</html></body>";
When I try it this way , the page shows me : " HTML::Extract=HASH(0x557e1ad591e0)->gethtml('http://192.168.0.104/' ,tagname=body,returntype=text)" I've tried without quotes and without generating a page but then it only shows that it can't be found (error 500); Where is my mistake . Please advice me !

Replies are listed 'Best First'.
Re^2: Proper use of HTML::Extract for extracting
by hippo (Archbishop) on Aug 26, 2018 at 13:41 UTC
    Where is my mistake . Please advice me !

    Method calls are not interpolated. If you move the method call outside the string it will actually be called. Here's an example as an SSCCE for which I've obviously replaced your private URL with a public one (I've also fixed the arguments to the gethtml method, your reversed closing tags, removed the indirect object notation and removed the unmatched <p1> element).

    #!/usr/bin/perl use strict; use warnings; use HTML::Extract; my $extractor = HTML::Extract->new; print "Content-type: text/html\n\n"; print "<html><body>\n"; print $extractor->gethtml('http://perlsphere.net/', 'tagname=body', 'returntype=text'); print "</body></html>";

    This could still be improved further but at least it shows you some working code. Enjoy.

      Thank you ! This helped a lot. But it returns the whole content of the web page. I've tried to change tagname=body to tagname=form but it only returns blank page

        Are you expecting to see the text you typed into the input box from this page ?

        <!DOCTYPE html> <html> <head> <title>Title</title> </head> <body> <form name="MyForm" action="/cgi-bin/ex.cgi",method="post",id="f1"> <input type="text" name="textfield"> </form> </body> </html>

        Why don't you want to use the CGI module ?

        poj

        there is no form tag on perlsphere.net.