如何使用Perl解析HTML? [英] How do I parse HTML with Perl?

查看:112
本文介绍了如何使用Perl解析HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也是编程和学习Perl的新手.

I'm new to programming and learning Perl as well.

这是我的问题:如何使用Perl模块在Perl中解析下面的数据?

Here is my question: How can I parse the data below in Perl using Perl modules?

<h4>This is the line</h4>
abc : 130.65 TB<br>
dif : 74.52 TB<br>
asw : 56.13 TB<br>
qwe : 57<br>

这是来自网页的示例数据,我想要类似的输出

This is the sample data from a webpage and I want an output like

abc = 130.65 TB
dif = 74.52 TB
asw = 56.13 TB
qwe = 57

有人可以帮助我吗?

推荐答案

使用HTML解析模块,例如 HTML :: TreeBuilder .

Use an HTML parsing module like HTML::Parser or HTML::TreeBuilder.

如果您只是尝试提取文本并剥离所有标签,那么它应该很简单:

If you are just trying to extract the text and strip all the tags, then it should be as simple as:

    use HTML::TreeBuilder;
    my $tree = HTML::TreeBuilder->new();
    $tree->parse( $YOUR_HTML_TEXT );
    $tree->eof();
    my $just_the_text = $tree->as_text();
    $tree->delete;

您还可以检查 http://htmlparsing.com/perl.html 了解有关解析HTML的更多信息使用Perl.

You can also check http://htmlparsing.com/perl.html for more on parsing HTML with Perl.

这篇关于如何使用Perl解析HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆