http://qs321.pair.com?node_id=11117607

zesys has asked for the wisdom of the Perl Monks concerning the following question:

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"; } } } }