in reply to Syntax error for WWW::Mechanize

There looks to be a subroutine name missing there.


Perl is Huffman encoded by design.

Replies are listed 'Best First'.
Re^2: Syntax error for WWW::Mechanize
by lampros21_7 (Scribe) on Jul 30, 2005 at 12:58 UTC
    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.

      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");

      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.