I am trying to write some code, and as a newbie, have some issues. I am trying to parse some HTML pages of some college athletic directories and get a list of all the coaches. I want to go through the page until i match a "section" regex, grab each row (tr) after, until i find another match for my section regex, then start again. I have figured out how to get the sport, and first coach under the heading, but cannot get where i can grab all the coaches under the heading until the next heading match. See my code below:

while ($content =~ m/<(td|th).*?<strong>(<.*?>)?(&nbsp;)?(?<sport>([(] +?(Women('|&#39;)s|Men('|&#39;)s|W|M)?[)]?(\s|&nbsp;)?)?(Archery|Badmi +nton|Baseball|Basketball|Bowling|Cross Country|Track (&|&amp;|[Aa]nd) + Field|Equestrian|Fencing|Field Hockey|Football|Golf|Gymnastics|Ice H +ockey|Lacrosse|Rowing|Rifle|Rugby|Skiing|Soccer|Softball|Squash|Swimm +ing ([Aa]nd |\s?[\/-]\s?|)Diving|Swimming|Diving|Synchronized Swim|Te +am Handball|Handball|Tennis|Volleyball|Water Polo|Wrestling)(\s?[-,]\ +s?)?\s?[(]?(Women(('|&#39;)s)?|Men(('|&#39;)s)?|W|M)?[)]?):?(.*?)?<\/ +(strong|br)>/gi) { print $+{sport} . "\r\n"; if ($content =~ m/\G.*?<tr.*?>(.*?)<\/tr>/sgc) { my $coach_info = $1; while ($coach_info =~ m/<td.*?>(.*?)<\/td>/mg) { print $1 . "\r\n"; } } }

Any ideas?


In reply to Parsing HTML Pages by SteveBo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.