Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I don't have any experience with HTML::FormatText, but LWP and HTML::TreeBuilder are rather dear to my heart. Try out the following code, I think it will get you closer to what you want. I just put the links in line with the text they were associated to, but you could easily print a footnote an push them into an array.
use strict; use LWP::UserAgent; use HTML::TreeBuilder; my $ua = LWP::UserAgent->new; my $page = $ua->LWP::UserAgent::get("http://www.databasefootball.com/b +oxscores/scheduleyear.htm?yr=1985&lg=nfl", 'User-Agent'=>'Mozilla/5.0'); my $tree = HTML::TreeBuilder->new; $tree->parse_content($page->decoded_content); #$tree->dump; foreach my $table ($tree->look_down('_tag', 'table')) { print "###Table###\n"; foreach my $row ($table->look_down('_tag', 'tr', sub { $_[0]->look +_up('_tag', 'table') == $table; })) { if ($row->as_text =~ / at /) { my $c = 0; foreach my $col ($row->look_down('_tag', qr/^t[dh]$/, sub +{ $_[0]->look_up('_tag', 'tr') == $row; })) { if ($c++) { print " "; } printf "%s", $col->as_text; if ($col->look_down('href', qr/./)) { printf " [%s]", $col->look_down('href', qr/./)->at +tr('href'); } } print "\n"; } else { printf "%s\n", $row->as_text; } } } exit;
When looking for rows and columns, I perform a look_up nexted inside my look_down. This may not be an issue for this webpage, but I deal with a lot of nested tables on my websites, and this eliminates processing a row within a nested table.

In reply to Re: problem HTML::FormatText::WithLinks::AndTables by DanEllison
in thread problem HTML::FormatText::WithLinks::AndTables by kevind0718

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found