Any help with this problem would be appreciated.
One ugly way
#!/usr/bin/perl -- use strict; use warnings; use Web::Scraper; use Data::Dump; my $sample = q{ <html><body> <h4 class="bla">July 12</h4> <p>Tim</p> <p>Jon</p> <h4 class="bla">July 13</h4> <p>James</p> <p>Eric</p> <p>Jerry</p> <p>Susie</p> <h4 class="date">July 14</h4> <p>Kami</p> <p>Darryl</p> </body></html> }; my $names = scraper { process q{//h4 | //p}, 'h4p[]', scraper { process q{//h4}, 'date' , 'text'; process q{//p}, 'person', 'text'; }; }; my $res = $names->scrape( $sample ); dd $res; { my @root; for my $tag ( @{ $res->{h4p} } ){ if( $$tag{date} ){ pop @root; # remove previous key push @root, {}, $$tag{date}; } if( $$tag{person} ){ push @{ $root[-2]->{ $root[-1] # key } } , $$tag{person}; } } pop @root if not ref $root[-1]; dd \@root; } __END__ { h4p => [ { date => "July 12" }, { person => "Tim" }, { person => "Jon" }, { date => "July 13" }, { person => "James" }, { person => "Eric" }, { person => "Jerry" }, { person => "Susie" }, { date => "July 14" }, { person => "Kami" }, { person => "Darryl" }, ], } [ { "July 12" => ["Tim", "Jon"] }, { "July 13" => ["James", "Eric", "Jerry", "Susie"] }, { "July 14" => ["Kami", "Darryl"] }, ]
In reply to Re: Extracting data-structure from HTML using Web::Scraper
by Anonymous Monk
in thread Extracting data-structure from HTML using Web::Scraper
by windowbreaker
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |