有没有办法使用Perl提取HTML页面标题?我知道它可以在表单提交期间作为隐藏变量传递,然后以Perl方式检索,但我想知道是否有一种方法可以在没有提交的情况下执行此操作?
就像,让我说我有一个像这样的HTML页面:
<html><head><title>TEST</title></head></html>
Run Code Online (Sandbox Code Playgroud)
然后在Perl中我想做:
$q -> h1('something');
Run Code Online (Sandbox Code Playgroud)
如何用<title>标签中包含的内容动态替换'something'?
我会用pQuery.它就像jQuery一样工作.
你可以说:
use pQuery;
my $page = pQuery("http://google.com/");
my $title = $page->find('title');
say "The title is: ", $title->html;
Run Code Online (Sandbox Code Playgroud)
替换东西是类似的:
$title->html('New Title');
say "The entirety of google.com with my new title is: ", $page->html;
Run Code Online (Sandbox Code Playgroud)
您可以将HTML字符串传递给pQuery构造函数,这听起来像您想要做的.
最后,如果要将任意HTML用作"模板",然后使用Perl命令"优化",则需要使用Template :: Refine.
| 归档时间: |
|
| 查看次数: |
5516 次 |
| 最近记录: |