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

后端 未结 3 1211
梦毁少年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:53

    You can use XPath to extract data from the very next table after the heading Node Object Methods, like so

    use Web::Scraper;
    
    my $html = do { local $/;  };
    
    my $methods = scraper {
        process '//h2[.="Node Object Methods"]/following-sibling::table[1]//tr/td[1]', 
            'renners[]' => 'TEXT';
    };  
    my $res = $methods->scrape( $html );
    
    say join "\n", @{ $res->{renners} };
    

    The output will be

    appendChild()
    cloneNode()
    compareDocumentPosition()
    getFeature(feature,version)
    getUserData(key)
    hasAttributes()
    hasChildNodes()
    insertBefore()
    

提交回复
热议问题