How do I extract an HTML title with Perl?

前端 未结 7 1937
粉色の甜心
粉色の甜心 2021-01-27 07:55

Is there a way to extract HTML page title using Perl? I know it can be passed as a hidden variable during form submit and then retrieved in Perl that way but I was wondering if

7条回答
  •  有刺的猬
    2021-01-27 08:33

    I would use pQuery. It works just like jQuery.

    You can say:

    use pQuery;
    my $page = pQuery("http://google.com/");
    my $title = $page->find('title');
    say "The title is: ", $title->html;
    

    Replacing stuff is similar:

    $title->html('New Title');
    say "The entirety of google.com with my new title is: ", $page->html;
    

    You can pass an HTML string to the pQuery constructor, which it sounds like you want to do.

    Finally, if you want to use arbitrary HTML as a "template", and then "refine" that with Perl commands, you want to use Template::Refine.

提交回复
热议问题