Hello Perl monks, first time asking a question. My apologies in advance if my post is not meeting house rules.

So, I am trying to extract information from a large html file.

Example blocks in the html:
--- <tr> <td class="confluenceTd">AL2H </td> <td class="confluenceTd">NANOMETRICSTITANSMA000357 </td> <td class="confluenceTd">2017-03-09T00:00:00.000Z </td> <td class="confluenceTd">2017-05-25T12:00:00.000Z </td> <td class="confluenceTd"><p><span class="image-wrap" style=""><img src +="/download/attachments/49449087/true.png?versio$ <td class="confluenceTd">48.38981 </td> <td class="confluenceTd">-123.48739 </td> <td class="confluenceTd">-29.0 </td> <td class="confluenceTd">&nbsp;</td> </tr> --- <tr> <td class="confluenceTd">BACAX </td> <td class="confluenceTd">RDIADCP600WH9339 </td> <td class="confluenceTd">2011-07-15T18:42:25.000Z </td> <td class="confluenceTd">2012-05-30T01:12:03.000Z </td> <td class="confluenceTd"><p><span class="image-wrap" style=""><img src +="/download/attachments/49449087/true.png?versio$ <td class="confluenceTd">48.316762 </td> <td class="confluenceTd">-126.050163 </td> <td class="confluenceTd">985.0 </td> <td class="confluenceTd">221.0 </td> </tr> ---

What my code does at the moment: Copy the first 4 lines of the first html block above, and print them with their meanings.

locationCode: AL2H deviceCode: NANOMETRICSTITANSMA000357 dateFrom: 2017-03-09T00:00:00.000Z dateTo: 2017-05-25T12:00:00.000Z

What I would like to achieve:

1. Do the same thing as above by looping through similar blocks.

2. Extract only blocks that have a sub-string "RDI" in their second line (eg., RDIADCP600WH9339 in the second block shown above).

I can try 2 if I can get help with 1.

Thank you.

My semi-working code is below. As you can see, I am storing the html page in a variable, $scrappy.

#!/usr/bin/perl use strict; use warnings; use utf8; use Term::ANSIColor qw(:constants); my $scrappy = `curl -s 'https://wiki.oceannetworks.ca/display/O2A/Available+Deployme +nts' 2>&1`; my $lineX; my $count = 0; foreach $lineX ( split /\n/, $scrappy ) { if ( $lineX =~ /^\s*$/ ) { # Skip white spaces or comment line next; } my @F = split( " ", $lineX ); my $mylen = length $lineX; if ( $mylen ge 2 ) { if ( ( $F[0] eq '<td' ) and ( $F[-1] eq '</td>' ) and ( $F[-1] ne '</p></td>' ) ) { my @f = split />/, $F[1]; $count++; if ( $count == 1 ) { print "locationCode: $f[1]\n"; } elsif ( $count == 2 ) { print "deviceCode: $f[1]\n"; } elsif ( $count == 3 ) { print "dateFrom: $f[1]\n"; } elsif ( $count == 4 ) { print "dateTo: $f[1]\n"; } } } }

In reply to Parsing a large html with perl by zesys

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.