我试图找到一个可以与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: $count\n"; foreach my $i ( $Feed->query('//item') ) { print $i->query('title')->text_content,"\n"; }