homepage Welcome to WebmasterWorld Guest from 54.226.136.179
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
parse html response using perl
PankajBansal

5+ Year Member



 
Msg#: 3930125 posted 5:54 am on Jun 10, 2009 (gmt 0)

I need to parse html response using perl. Could anyone please help

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3930125 posted 5:58 am on Jun 10, 2009 (gmt 0)

use HTML::TreeBuilder [search.cpan.org]

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3930125 posted 12:17 pm on Jun 10, 2009 (gmt 0)

you could start with this to make a request and handle the response:
#!/usr/local/bin/perl

use LWP::UserAgent;
use HTTP::Request;

my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30);
my $url = "http://example.com/";
my $header = HTTP::Request->new(GET => $url);
my $request = HTTP::Request->new('GET', $url, $header);
my $response = $agent->request($request);

# Check the outcome of the response
if ($response->is_success){

# parse your response here

}elsif ($response->is_error){
print $response->error_as_HTML;
}


janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3930125 posted 1:06 pm on Jun 10, 2009 (gmt 0)

I believe,
my $header = HTTP::Request->new(GET => $url);
should be
my $header = HTTP::Headers->new();
copy & pasted? ;)

and, to add, the HTML in phranque's example will be available in $response->content in the block where you'll parse it.

phranque

WebmasterWorld Administrator phranque us a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



 
Msg#: 3930125 posted 12:56 pm on Jun 11, 2009 (gmt 0)

yes, check that:
#!/usr/local/bin/perl

use LWP::UserAgent;
use HTTP::Request;

my $agent = LWP::UserAgent->new(env_proxy => 1,keep_alive => 1, timeout => 30);
my $url = "http://example.com/";
my $request = HTTP::Request->new('GET', $url);
my $response = $agent->request($request);

# Check the outcome of the response
if ($response->is_success){

# parse $response->content here

}elsif ($response->is_error){
print $response->error_as_HTML;
}


Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved