Re: regex on the fly on LWP

[email protected] (Rob Dixon)
Newsgroups perl.beginners
Message-ID <[email protected]>
Pat Rice wrote:
> hi all
> I want to know if there is a way of puilling out line by line, a
> www::Mechanize or LWP
> 
> so at the moment I'm doing:
> 
> 
> 
> 
>  1 #!/usr/bin/perl
>       2
>       3 # Include the WWW::Mechanize module
>       4 use WWW::Mechanize;
>       5
>       6
>       7 HTTP::Response;
>       8
> 
>      15
>      16 $url = "http://whatever.com/";
>      17
>      18
>      20 print "\n $url \n";
>      21
>      22 # Create a new instance of WWW::Mechanize
>      23 # enabling autoheck checks each request to ensure it was successful,
>      24 # producing an error if not.
>      25 my $mechanize = WWW::Mechanize->new(autocheck => 1);
>      26
>      27 # Retrieve the page
>      28 $mechanize->get($url);
>      29
>      30 # Assign the page content to $page
>      31 my $page = $mechanize->content;
>      32
>      33 # Output the page
>      34 print $page;
> 
> 
> 
> 
> so what I'm trying to do is do a regex on each line as I suck it in,
> and then print out the line, so I don't have to do a regex on a file.
> 
> so i would do a regex $page and what ever line would have the regex in
> would print it out.

Hi Pat

WWW::Mechanize is intended to emulate a web browser's functionality. If you need
lower level access then you should look at LWP, but remember that there is no
concept of a 'line' in HTML. You would need to parse the page as it arrives and
search for something like <p> or <br> elements in the content.

Perhaps if you explained your application properly we could help better?

Rob
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.