I want to extract the text only for heading Node Object Methods from a webpage. The specific HMTL part is as follows:
Node Object Properties
Web::Scraper can use nth_of_type
to choose the right table. There are two tables with the same class, so you can say table.reference:nth-of-type(2)
:
use v5.22;
use feature qw(postderef);
no warnings qw(experimental::postderef);
use Web::Scraper;
my $html = do { local $/; };
my $methods = scraper {
process "table.reference:nth-of-type(2) > tr > td > a", 'renners[]' => 'TEXT';
};
my $res = $methods->scrape( $html );
say join "\n", $res->{renners}->@*;
And here's a Mojo::DOM:
use Mojo::DOM;
my $html = do { local $/; };
my $dom = Mojo::DOM->new( $html );
say $dom
->find( 'table.reference:nth-of-type(2) > tr > td > a' )
->map( 'text' )
->join( "\n" );
I tried looking for a selector solution that could recognize the text in the h2
, but my kung fu is weak here.