How can I select from only one table with Web::Scraper?

后端 未结 3 1213
梦毁少年i
梦毁少年i 2021-01-25 06:19

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

3条回答
  •  广开言路
    2021-01-25 06:46

    Web::Query provides an almost identical solution to the Mojo::DOM solution proposed by brian d foy.

    use Web::Query;
    
    my $html = do { local $/;  };
    
    wq($html)
        ->find('table.reference:nth-of-type(2) > tr > td > a')
        ->each(sub {
            my ($i, $e) = @_;
            say $e->text();
        });
    

    However it looks like Mojo::DOM is the more robust library. For Web::Query to correctly match with its selector I had to edit the input provided in the question to add a root node surrounding all the other content.

    __DATA__
    
    ...
    
    

提交回复
热议问题