in reply to Re^2: Problem extracting an HTML table with Perl
in thread Problem extracting an HTML table with Perl

That is not what I see, and I note the OP used the look down method instead of the find method as you have in this post.

If I run

#!/usr/local/bin/perl use strict; use warnings; use autodie; use Data::Dump; use HTML::Tree; use LWP::Simple qw(get); my $content=get('http://www.ncbi.nlm.nih.gov/genome/?term=Xylella_fast +idiosa'); my $tree = HTML::Tree->new(); $tree->parse($content); my $data =$tree->look_down( '_tag' =>'div', class => 'genome_descr' ); print $data->as_HTML;
I get the output
<div class="genome_descr"><p><b>Submitter: </b><a href="http://aeg.lbi +.ic.unicamp.br/xf/" target="_blank">Sao Paulo state (Brazil) Consorti +um</a></div>
If I run with
my @data =$tree->look_down( '_tag' =>'div', class => 'genome_descr' );
instead, I get 2 results. How does this compare for you?

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^4: Problem extracting an HTML table with Perl
by Sosi (Sexton) on Aug 11, 2014 at 17:56 UTC

    I had missed that of the find. I now found that I chose the wrong tag given that I wanted the list that shows after this tag, but I'll get to that later.

    Indeed I now see that I cannot dd $data as it dumps everything - the print $data->as_HTML solves the problem. One more question: in your second example, how did you print the data?

    Thanks so much!

      For the list context call, I actually only output
      print 0+ @data;
      to tell me the length of the array. If I wanted to print both terms, I'd either use a map and a join
      print join "\n", map $_->as_HTML, @data;
      or just use Foreach Loops:
      for my $datum (@data) { print $datum->as_HTML, "\n"; }

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.