加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

我可以使用什么模块来解析Perl CGI脚本中的RSS源?

发布时间:2020-12-16 06:27:10 所属栏目:大数据 来源:网络整理
导读:我试图找到一个可以与Perl CGI脚本一起使用的RSS解析器.我找到了simplepie,这在 PHP脚本中非常容易使用.不幸的是,这不适用于Perl CGI脚本.如果有什么比easypie更容易使用,请告诉我. 我遇到了这个RssDisplay但是我不确定它的用法以及它有多好. 解决方法 从 CP
我试图找到一个可以与Perl CGI脚本一起使用的RSS解析器.我找到了simplepie,这在 PHP脚本中非常容易使用.不幸的是,这不适用于Perl CGI脚本.如果有什么比easypie更容易使用,请告诉我.

我遇到了这个RssDisplay但是我不确定它的用法以及它有多好.

解决方法

从 CPAN: XML::RSS::Parser.

07001 is a lightweight liberal parser of RSS feeds. This parser is “liberal” in that it does not demand compliance of a specific RSS version and will attempt to gracefully handle tags it does not expect or understand. The parser’s only requirements is that the file is well-formed XML and remotely resembles RSS.

#!/usr/bin/perl

use strict; use warnings;

use XML::RSS::Parser;
use FileHandle;

my $parser = XML::RSS::Parser->new;

unless ( -e 'uploads.rdf' ) {
    require LWP::Simple;
    LWP::Simple::getstore(
        'http://search.cpan.org/uploads.rdf','uploads.rdf',);
}
my $fh = FileHandle->new('uploads.rdf');
my $feed = $parser->parse_file($fh);

print $feed->query('/channel/title')->text_content,"n";

my $count = $feed->item_count;
print "# of Items: $countn";

foreach my $i ( $feed->query('//item') ) {
    print $i->query('title')->text_content,"n";
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读