in reply to Re: Syntax error for WWW::Mechanize
in thread Syntax error for WWW::Mechanize

What subroutine is missing? I am basically trying to save as a string the non-HTML content of a website using that part od the WWW::Mechanize code.

Replies are listed 'Best First'.
Re^3: Syntax error for WWW::Mechanize
by jhourcle (Prior) on Jul 30, 2005 at 13:32 UTC

    You had:

    $stripped_html[$x] = $webcrawler( format => "text");

    $webcrawler is a scalar. If it were a scalar code ref, you could do &$webcrawler( format => 'text' ), but it looks to be to be a WWW::Mechanize object. So, what you have is a scalar, then two more scalars in parenthesis.

    You need some sort of operator between the '$webcrawler' and the parenthesis. More than likely, based on the parentheis, you're missing a method call:

    $webcrawler->method( format  => 'text' );

    So, what method call takes a hash as its argument, and one of the keys is format? We look at the documentation for WWW::Mechanize, and search for the string 'format', and we find the following:

    $mech->content( format => "text" )

    So, I can only guess that you should have written:

    $stripped_html[$x] = $webcrawler->content( format => "text");
Re^3: Syntax error for WWW::Mechanize
by GrandFather (Saint) on Jul 30, 2005 at 13:27 UTC

    The following code may do something like what you are trying to achieve:

    use warnings; use strict; use WWW::Mechanize; use HTML::TreeBuilder; my $webcrawler = WWW::Mechanize->new(); my $page = $webcrawler->get ('http://perlmonks.org/?node_id=479598'); my $tree = HTML::TreeBuilder->new_from_content ($page->as_string ()); print $tree->as_text ();

    Perl is Huffman encoded by design.