LWP::UserAgent - 01 - Basics
#!/usr/bin/perl -w use strict; use LWP 5.64; # Loads all important LWP classes, and makes # sure your version is reasonably recent. my $url = 'http://freshair.npr.org/dayFA.cfm?todayDate=current'; my $browser = LWP::UserAgent->new; my $response = $browser->get( $url ); die "Can't get $url -- ", $response->status_line unless $response->is_success; die "Hey, I was expecting HTML, not ", $response->content_type unless $response->content_type eq 'text/html'; # or whatever content-type you're dealing with. # Otherwise, process the content somehow: if ($response->content =~ m/jazz/i) { print "They're talking about jazz today on Fresh Air!\n"; } else {print "Fresh Air is apparently jazzless today.\n"; }
LWP::UserAgent + HTTP::Response
Slideshow ^ |< << Slide 30 of 40 >> >| |