in reply to Key/Value pair from GET
____________#!/usr/bin/perl -w use strict; use URI; # in the realworld, it comes from somewhere else my $page_content = <<'EOT'; <a href="thepage.jsp?siteId=1§ionId=443&"> <span class="small">Geography</span></a> EOT # the following regex will simply catch any anchor tags, # making no assumptions about their structure while($page_content =~ /<a\s[^>]*?href="([^"]+)"[^>]*>(.*?)<\/a>/sgi) +{ my $url = new URI $1; my %params = $url->query_form; # now we let URI do the dirty job f +or us next unless exists $params{sectionId}; # was there a sectionId par +ameter? # if we're still in the loop here, there was my $text = $2; $text =~ s/<[^>]*>//sgi; # strip all tags from the anchor's inner +text $text =~ s/^\s+//sgi; # then strip any whitespace from the front $text =~ s/\s+$//sgi; # and from the end print "$params{sectionId},$text\n"; # some pretty output }
|
|---|