Don't listen to the insane ramblings of the Anonymous Monk.

If you have to work some HTML-file, your best bet is one of the parser modules such as HTML::Parser.

Looking at the structure of your HTML file, you will see that the info you are looking for is always contained within a a-tag and more specifically within the href-attribute in that tag.

With HTML::Parser it is trivially easy to extract all a-tags from the HTML file and then use a regex to see if the attribute contains the string 'CIS Report for followed by a date. Extracting the date and the filename is simple. You probably just want to extract the filename for the date of today. That is left as an exercise for you.

Here follows the basic program:

use strict; use HTML::Parser (); # Create parser object my $p = HTML::Parser->new( api_version => 3, start_h => [\&a_tag, "tag, attr"], ); $p->parse_file('c:/data/perl/script/volvo.html'); sub a_tag { my $tag = shift; return unless $tag eq 'a'; my $hashref = shift; return unless $hashref->{'href'}=~m|'CIS Report for (\d{2}/\d{2}/\ +d{4})|; my $date = $1; (my $file) = $hashref->{'href'}=~m|PopupInfo\('(.*pdf)|; print "$date: $file\n"; }
And it prints:
12/26/2007: CE1B85BDDDE8F58A852573BD003B1FBC/$file/vcmorarorp346601226 +200712262007944204.pdf 12/26/2007: CE1B85BDDDE8F58A852573BD003B1FBC/$file/vcmorarorp346601226 +200712262007944204.pdf 12/25/2007: C0FBD06860B80B7B852573BC003B3738/$file/vcmorarorp346601225 +200712252007939900.pdf 12/25/2007: C0FBD06860B80B7B852573BC003B3738/$file/vcmorarorp346601225 +200712252007939900.pdf 12/24/2007: 31ED64C95AFF1A06852573BB003F55E5/$file/vcmorarorp346601224 +200712242007930592.pdf 12/24/2007: 31ED64C95AFF1A06852573BB003F55E5/$file/vcmorarorp346601224 +200712242007930592.pdf
Remark: It seems each filename is mentioned twice in the HTML-page.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: parse a changing html table by CountZero
in thread parse a changing html table by gary441

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.