【问题标题】:Mojo::DOM and Text Method to remove spacesMojo::DOM 和 Text 删除空格的方法
【发布时间】:2019-09-03 20:21:44
【问题描述】:

我有以下代码使用 Mojo::DOM 来获取文本

my $text =ua->get('https://my_site.org'.$_)->res->dom->at('div.container-fluid h1')->text;

而h1下的文字如果采用以下格式:

<h1>
                       my_text                    </h1>

$text 带有标题和尾随空格

我可以这样做来删除标题和尾随空格

  $text =~ s/^\s+//;
  $text=~ s/\s+$//;

但我想知道是否可以使用 mojolicious 功能来做到这一点?

【问题讨论】:

    标签: perl mojolicious mojo-useragent mojo-dom


    【解决方案1】:

    Mojo::Util 提供 trim 应该做你想做的事:

    my $trimmed = trim $str;

    从字符串的两端修剪空白字符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2015-02-12
      • 1970-01-01
      • 2012-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多