Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Are you sure? In that case I would guess that he must also remove the 'tr' from his further process statements.

Yup, I'm sure, and oddly no, there is no need to remove tr.

It would have been easier to see if ag4ve had posted runnable code , but I adapted eg/dave-trailer-HD.pl

I have no idea if this is intended behavior of this module

#!/usr/bin/perl -- use strict; use warnings; use Data::Dumper; use Web::Scraper; my $html_content = <<'__HTML__'; <html> <body> <div></div> <div id="wrapper"> <div></div> <div id="outer"> <div id="inner"> <div></div> <div id="center"> <div></div> <div id="main"> <div></div> <div> <table id="wrappedcontent"> <tbody class="shnitzel" bgcolor='red'> <tr> <td> <table class="someclass" style="width:508px;" id="Any_20"> <tbody> <tr> <td><strong>key1</strong></td> <td>val1</td> </tr> <tr> <td><strong>key2</strong></td> <td>val2</td> </tr> <tr> <td><strong>key3</strong></td> <td>val3</td> </tr> <tr> <td><strong>key4</strong></td> <td>val4</td> </tr> <tr> <td><strong>key5</strong></td> <td>val5</td> </tr> <tr> <td><strong>key6</strong></td> <td>val6</td> </tr> <tr> <td><strong>key7</strong></td> <td>val7</td> </tr> <tr> <td><strong>key8</strong></td> <td>val8</td> </tr> <tr> <td><strong>key9</strong></td> <td>val9</td> </tr> <tr> <td><strong>key10</strong></td> <td>val10</td> </tr> <tr> <td><strong>key11</strong></td> <td>val11</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </div> </div> </div> </div> </div> </div> </body> </html> __HTML__ my @pdata; push @pdata, scraper { process '//*/table[@class="someclass"]', 'table[]' => scraper { process '//tr/td[1]', 'name' => 'TEXT'; process '//tr/td[2]', 'attr' => 'TEXT'; }; }; push @pdata, scraper { process '//*/table[@class="someclass"]', 'table[]' => scraper { process '//tr/td[1]', 'name[]' => 'TEXT'; process '//tr/td[2]', 'attr[]' => 'TEXT'; }; }; push @pdata, scraper { process '//*/table[@class="someclass"]//tr', 'table[]' => { process('//tr/td[1]', 'name[]' => 'TEXT'), process('//tr/td[2]', 'attr[]' => 'TEXT'), }; }; push @pdata, scraper { process '//*/table[@class="someclass"]//tr', 'table[]' => scraper { process '//tr/td[1]', 'name' => 'TEXT'; process '//tr/td[2]', 'attr' => 'TEXT'; }; }; push @pdata, scraper { process '//*/table[@class="someclass"]//tr', 'table[]' => scraper { process '//tr/td[1]', 'name' => 'TEXT'; process '//tr/td[2]', 'attr' => 'TEXT'; }; result 'table'; }; push @pdata, scraper { process '//*/table[@class="someclass"]//tr', 'table[]' => scraper { process '//tr/td[1]', 'name[]' => 'TEXT'; process '//tr/td[2]', 'attr[]' => 'TEXT'; }; }; for my $pagedata ( @pdata ){ my $res = $pagedata->scrape( \$html_content ) or die "Can't define content to parser $!"; print Dumper( $res ), "\n\n"; } __END__ $VAR1 = { 'table' => [ { 'name' => 'key1', 'attr' => 'val1' } ] }; $VAR1 = { 'table' => [ { 'name' => [ 'key1', 'key2', 'key3', 'key4', 'key5', 'key6', 'key7', 'key8', 'key9', 'key10', 'key11' ], 'attr' => [ 'val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val9', 'val10', 'val11' ] } ] }; $VAR1 = { 'table' => [ undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, undef ], 'name' => [ 'key1val1key2val2key3val3key4val4key5val5key6val +6key7val7key8val8key9val9key10val10key11val11', 'key1', 'key2', 'key3', 'key4', 'key5', 'key6', 'key7', 'key8', 'key9', 'key10', 'key11' ], 'attr' => [ 'val1', 'val2', 'val3', 'val4', 'val5', 'val6', 'val7', 'val8', 'val9', 'val10', 'val11' ] }; $VAR1 = { 'table' => [ { 'name' => 'key1', 'attr' => 'val1' }, { 'name' => 'key2', 'attr' => 'val2' }, { 'name' => 'key3', 'attr' => 'val3' }, { 'name' => 'key4', 'attr' => 'val4' }, { 'name' => 'key5', 'attr' => 'val5' }, { 'name' => 'key6', 'attr' => 'val6' }, { 'name' => 'key7', 'attr' => 'val7' }, { 'name' => 'key8', 'attr' => 'val8' }, { 'name' => 'key9', 'attr' => 'val9' }, { 'name' => 'key10', 'attr' => 'val10' }, { 'name' => 'key11', 'attr' => 'val11' } ] }; $VAR1 = [ { 'name' => 'key1', 'attr' => 'val1' }, { 'name' => 'key2', 'attr' => 'val2' }, { 'name' => 'key3', 'attr' => 'val3' }, { 'name' => 'key4', 'attr' => 'val4' }, { 'name' => 'key5', 'attr' => 'val5' }, { 'name' => 'key6', 'attr' => 'val6' }, { 'name' => 'key7', 'attr' => 'val7' }, { 'name' => 'key8', 'attr' => 'val8' }, { 'name' => 'key9', 'attr' => 'val9' }, { 'name' => 'key10', 'attr' => 'val10' }, { 'name' => 'key11', 'attr' => 'val11' } ]; $VAR1 = { 'table' => [ { 'name' => [ 'key1' ], 'attr' => [ 'val1' ] }, { 'name' => [ 'key2' ], 'attr' => [ 'val2' ] }, { 'name' => [ 'key3' ], 'attr' => [ 'val3' ] }, { 'name' => [ 'key4' ], 'attr' => [ 'val4' ] }, { 'name' => [ 'key5' ], 'attr' => [ 'val5' ] }, { 'name' => [ 'key6' ], 'attr' => [ 'val6' ] }, { 'name' => [ 'key7' ], 'attr' => [ 'val7' ] }, { 'name' => [ 'key8' ], 'attr' => [ 'val8' ] }, { 'name' => [ 'key9' ], 'attr' => [ 'val9' ] }, { 'name' => [ 'key10' ], 'attr' => [ 'val10' ] }, { 'name' => [ 'key11' ], 'attr' => [ 'val11' ] } ] };

In reply to Re^4: web::scraper using an xpath by Anonymous Monk
in thread web::scraper using an xpath by ag4ve

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (17)
    As of 2014-12-18 14:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (56 votes), past polls