Gary Nielson <[EMAIL PROTECTED]> wrote:

: I am trying to get the first paragraph of an article
: from an html document. I am trying to do this by
: getting the document from the web, using 'join' to
: make many lines one line, and then trying to isolate
: the text I want. Is this workable?
: 
: Here's an example of the area of a longer html
: document that I am trying to parse. (The dateline
: classes do not appear in all articles. I figure I
: can get rid of the remaining tags later in the
: script.)

    I have used HTML::TokeParser to parse html via
lwp in the past with great success. I used it to
parse a few thousand messages on a BBS.

    Here's another one I did to rip apart new
messages to provide RSS feeds. As you can see it
allows matching with or without regexes.

while ( my $token = $page->get_tag( 'div' ) ) {
    last if $token->[1]{class} =~ /ABMSGLIST/i;
}

while ( $page->get_tag( 'table' ) ) {
    last unless $page->get_tag( 'table' );

    $page->get_tag( 'font' );
    $page->get_tag( 'a' );

    my $token   = $page->get_tag( 'a' );
    my $link    = "$root/$token->[1]{href}";

    next unless $page->get_tag( 'font' );
    my $title       =  $page->get_trimmed_text( '/font' );
    next if $title  =~ /new member/i;

    next unless $page->get_tag( 'a' );
    $title .= sprintf '(by %s)', $page->get_trimmed_text( '/a' );

    next unless $page->get_tag( 'td' );
    my $date    = $page->get_trimmed_text( '/td' );
    $date       = (split /,/, $date)[0];

    $rss->add_item(
        title       => $q->escapeHTML( $title ),
        link        => $q->escapeHTML( $link  ),
        description => $date

        ) if date_comp_today( $date );

}

HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to