Hello,
I posted this question a few days ago, hoping to resolve my problem, which is that I am able to successfully retrieve the table data from a website but the 4 columns each come out on a separate line. I received a reply from someone with the suggestion to chomp newlines, but I have tried a whole bunch of variations and I am getting nowhere. A big part of my problem is lack of experience in this area (with tables). Can someone please straighten me out on where I am going wrong? What I am hoping to get is something like this:
a1,a2,a3,a4
b1,b2,b3,b4
.
.
.
But it's just not happening. Every field i.e., a1, a2, etc., is coming out on separate lines. I need some heavy-duty expert advice. This is the code I have so far:
#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;
use HTML::TableExtract;
my $url;
$url="http://www.earnings.com/fin/earnListing.jsp?tckr=&exch=&eff=&dat
+e=2003-05-04";
my $content=get $url;
my $te = new HTML::TableExtract( headers =>
[qw(Company Symbol Estimate Actual)] );
$te->parse($content);
# Examine all matching tables
foreach my $ts ($te->table_states) {
print "Table (", join(',', $ts->coords), "):\n";
foreach my $row ($ts->rows) {
print join(',', @$row), "\n";
}
}
Again, any help would be greatly appreciated.
edited: Mon May 12 14:17:10 2003
by jeffa - code tags, title change (was: This Newbie Needs Perl Monks Help In Displaying Web Table Data Properly)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.