in reply to Best way to search for specifics in a webpage?
Personally I would use HTML::TableExtract which is a subclass of HTML::Parser for everything. If you want a fragile regex solution you could do (assuming html page is in the scalar $html):
my ($location) = $html =~ m/Location:\s*([^<]+)/i; my ($time) = $html =~ m/Time:\s*([^<]+)/i; my ($days) = $html =~ m/Days:\s*([^<]+)/i; my ($instructor) = $html =~ m/Instructor:\s*([^<]+)/i; # if you want plain text you will need to do this $location = unescapeHTML($location); $time = unescapeHTML($time); $day = unescapeHTML($days); $instructor = unescapeHTML($instructor); # this unescapes common cases, not all possible cases. For perfection +-> CPAN sub unescapeHTML { my( $unescape ) = @_; return undef unless defined($unescape); $unescape=~ s[&(.*?);]{ local $_ = $1; /^amp$/i ? '&' : /^quot$/i ? '"' : /^gt$/i ? '>' : /^lt$/i ? '<' : /^nbsp/i ? ' ' : /^#(\d+)$/ ? chr($1) : /^#x([0-9a-f]+)$/i ? chr(hex($1)) : $_ }gex; return $unescape; }
If you use arrays rather than scalars for location et al and add a /g you will get all the locations on the page...
my @location = $html =~ m/Location:\s*([^<]+)/gi; # first match will be in $loction[0] and last match (no suprisingly) i +n $location[-1]
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Best way to search for specifics in a webpage?
by Anonymous Monk on Dec 27, 2002 at 11:10 UTC | |
by tachyon (Chancellor) on Dec 27, 2002 at 11:36 UTC |