in reply to Re: Parse HTML Code for hidden values
in thread Parse HTML Code for hidden values

So, I have to admit... I am a bit more of a "copy-paste" coder... I get the logic, but not always the syntax. :-) I see what you are saying here, and I think it is my answer, but for the life of me I can't get the loop to run. I was getting no data out of this, so I put a debug statement in the "for" loop, and it doesn't appear to be running past the first 2 lines. I can dump $response, and I get valid data..
Dumper($response->{body}->{table})
Here is a snipet of my test code:
print "body-table is:", Dumper($response->{body}->{table}), "\n"; print "=============================================================== +===\n"; my %rec; for (@{ $response->{body}{table} }) { print "Data Record Found - Body Table \n"; my ($key) = grep $_ ne 'content', keys(%{$_->{tr}{td}}); my $val = $_->{tr}{td}{$key}; $rec{$key} = $val; } print "rec is:", Dumper($rec), "\n";
And the result is:
body-table is:$VAR1 = [ { 'tr' => { 'td' => { 'ReturnStatus' => 'Completed', 'content' => "Return Status:\x{a0}" } } }, { 'tr' => [ { 'td' => { 'StateInfo' => '12345', 'content' => "StateInfo:\x{a0}" } }, { 'td' => { 'MultipleSubAccount' => 'N', 'content' => "Multiple Sub Account:\x{a0 +}" } }, { 'td' => { 'Count' => '1', 'content' => "Count:\x{a0}" } }, { 'td' => { 'content' => "Default Account:\x{a0}", 'DefaultAccount' => '1234567' } }, { 'td' => { 'content' => "Caller Phone Number:\x{a0} +", 'CallerPhoneNumber' => '214-555-1212' } }, { 'td' => { 'CallerHouseNumber' => ' 123', 'content' => "Caller House Number:\x{a0} +" } }, { 'td' => { 'ApartmentNum' => {}, 'content' => "Apartment Num:\x{a0}" } }, { 'td' => { 'CallerSalutation' => {}, 'content' => "Caller Salutation:\x{a0}" } }, { 'td' => { 'CallerFirstName' => 'JOHN', 'content' => "Caller First Name:\x{a0}" } }, { 'td' => { 'content' => "Caller Last Name:\x{a0}", 'CallerLastName' => 'SMITH' } }, { 'td' => { 'content' => "Salutation:\x{a0}", 'Salutation' => {} } }, { 'td' => { 'FirstName' => 'JOHN', 'content' => "FirstName:\x{a0}" } }, { 'td' => { 'content' => "MiddleInitial:\x{a0}", 'MiddleInitial' => {} } }, { 'td' => { 'LastName' => 'SMITH', 'content' => "LastName:\x{a0}" } }, { 'td' => { 'Honorific' => {}, 'content' => "Honorific:\x{a0}" } }, { 'td' => { 'content' => "FullName:\x{a0}", 'FullName' => 'JOHN SMITH' } }, { 'td' => { 'OtherName' => {}, 'content' => "OtherName:\x{a0}" } }, { 'td' => { 'OtherNameUsage' => {}, 'content' => "OtherNameUsage:\x{a0}" } }, { 'td' => { 'HouseNumber' => '123', 'content' => "House Number:\x{a0}" } }, { 'td' => { 'content' => "UnitNumber:\x{a0}", 'UnitNumber' => {} } }, { 'td' => { 'content' => "City:\x{a0}", 'City' => 'ANYTOWN' } }, { 'td' => { 'content' => "State:\x{a0}", 'State' => 'OH' } }, { 'td' => { 'Zip' => '12345-1234', 'content' => "Zip:\x{a0}" } }, { 'td' => { 'AddressLine1' => 'JOHN SMITH', 'content' => "AddressLine1:\x{a0}" } }, { 'td' => { 'AddressLine2' => '123 W MAIN ST', 'content' => "AddressLine2:\x{a0}" } }, { 'td' => { 'AddressLine3' => 'ANYTOWN OH 12345-123 +4', 'content' => "AddressLine3:\x{a0}" } }, { 'td' => { 'AddressLine4' => {}, 'content' => "AddressLine4:\x{a0}" } }, { 'td' => { 'AddressLine5' => {}, 'content' => "AddressLine5:\x{a0}" } }, { 'td' => { 'content' => "AddressLine6:\x{a0}", 'AddressLine6' => {} } }, { 'td' => { 'AddressLine7' => {}, 'content' => "AddressLine7:\x{a0}" } }, { 'td' => { 'content' => "AddressLine8:\x{a0}", 'AddressLine8' => {} } }, { 'td' => { 'a' => { 'href' => 'lastpmt.html?stateInfo +=12345', 'content' => 'Last Payment Info' } } }, { 'td' => { 'a' => { 'href' => 'serverrform1.html?stat +eInfo=12345', 'content' => 'Service Error' } } }, { 'td' => { 'a' => { 'href' => 'stopinfoform.html?stat +eInfo=12345', 'content' => 'Stop/Start' } } }, { 'td' => { 'a' => { 'href' => 'renewinfoform.html?sta +teInfo=12345', 'content' => 'Make a Payment' } } }, { 'td' => { 'a' => { 'href' => 'loginform.html', 'content' => 'Change Login' } } } ] } ]; ================================================================== Data Record Found - Body Table Data Record Found - Body Table rec is:$VAR1 = undef;
Any help is GREATLY appreciated!! Thanks!

Replies are listed 'Best First'.
Re^3: Parse HTML Code for hidden values
by choroba (Cardinal) on Aug 30, 2010 at 14:19 UTC
    Unlike in your HTML example in the OP, the dump suggests you have many td's in one tr, not one td per tr. You can for example add an inner loop over the td's - but if the structure of your data is not fixed, you can have similar problems every time another level of nesting appears!
      Using ForceArray => [qw( table tr td )],
      my %rec; for my $table (@{ $response->{body}{table} }) { for my $tr (@{ $table->{tr} }) { for my $td (@{ $tr->{td} }) { my ($key) = grep $_ ne 'content', keys(%$td); $rec{$key} = $td->{$key}; } } } print("$rec{LastName}\n"); # For example