Really struggling with what is going on.. I am writing a little spider to grab all the ads off a site and you have to pass a "Count=n" variable in the URL to get more ads. When set to zero, you get the first 10 ads, then set to Count=10 to get the next 10 and so on...
#!/usr/bin/perl use lib qw( ..); use HTML::TableExtract; use LWP::Simple; use Data::Dumper; my $te = new HTML::TableExtract( depth=>3,count=>0); # which table do +we want # Get the total number of records according to MDJONLINE my $content = get( "http://www.mdjonline.com/classifieds/legals/index.inn?loc=detail&main +=Legals&sub=Foreclosures&Count=0") || die "Couldn't get URL\n"; $content =~ m{Total\s?ads: (\d+)} || die "No dice\n"; my $total = $1; # Set some intial values for record number and iterations my $iter = ($total - ($total % 10)); # calculate iterations to nearest + num divisible by 10 my $recnum = 0; # number of start record for next dump while($recnum <= $iter) { my $mdjURL = "http://www.mdjonline.com/classifieds/legals/inde +x.inn?loc=detail&main=Legals&sub=Foreclosures&Count=".$recnum; my $content = get($mdjURL); $te->parse($content); foreach $ts ($te->table_states) { foreach $row ($ts->rows) { print Dumper $row; } } $recnum += 10; }
I separated out the URL as a var so I could debug it and verify that it is INDEED incrementing the URL by 10, and it is, but it returns the same 10 ads until it hits $total, so of course I have 74 identical 10-ad blocks (not what I'm after obviously). I have tried just about everything I can think of and about ready to impail myself with a grapefruit spoon in the front yard.. hmm.. wonder why we call it "grape"frut.. sure as hell doesn't look like a grape.

If anyone out there can help, I would be EVER so appreciative. =)

UPDATE:
I figured it out.
#!/usr/bin/perl use lib qw( ..); use HTML::TableExtract; use LWP::Simple; use Data::Dumper; # Get the total number of records according to MDJONLINE my $content = get( "http://www.mdjonline.com/classifieds/legals/index.inn?loc=detail&main +=Legals&sub=Foreclosures&Count=0") || die "Couldn't get URL\n"; $content =~ m{Total\s?ads: (\d+)} || die "No dice\n"; my $total = $1; # Set some intial values for record number and iterations my $iter = ($total - ($total % 10)); # calculate iterations to nearest + num divisible by 10 my $recnum = 0; # number of start record for next dump while($recnum <= $iter) { my $te = new HTML::TableExtract( depth=>3,count=>0); my $mdjURL = "http://www.mdjonline.com/classifieds/legals/inde +x.inn?loc=detail&main=Legals&sub=Foreclosures&Count=".$recnum; my $content = get($mdjURL); $te->parse($content); foreach $ts ($te->table_states) { foreach $row ($ts->rows) { print Dumper $row; } } $recnum += 10; }
Declaring $te inside the while loop makes it reinitialize each time.

In reply to HTML::Table::Extract by carric

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.