Perl parse links from HTML Table

后端 未结 2 1463
花落未央
花落未央 2021-01-25 12:51

I\'m trying to get links from table in HTML. By using HTML::TableExtract, I\'m able to parse table and get text (i.e. Ability, Abnormal in below example) but cannot get link tha

2条回答
  •  春和景丽
    2021-01-25 13:31

    HTML::LinkExtor, passing the extracted table text to its parse method.

    my $le = HTML::LinkExtor->new();
    
    foreach $ts ($te->tables){
        foreach $row ($ts->rows){
            $le->parse($row->[0]);
            for my $link_tag ( $le->links ) {
                my ($tag, %links) = @$link_tag;
                # next if $tag ne 'a'; # exclude other kinds of links?
                print for values %links;
            }
        }
    }
    

提交回复
热议问题