如何在Linux下使用perl编程读取rss文件?
先让大家看看效果吧:
yahoo news : http://thefirstwind.ddo.jp/~devuser/cgi-bin/yahoonews.pl
csdn personal blog : http://thefirstwind.ddo.jp/~devuser/cgi-bin/csdnblog_thefirstwind.pl
1 首先是前期的准备
编程环境: RedHat Linux 9.0 perl v5.8.8
软件包: LWP::Simple ,use XML::RSS;
为了配好适合的软件环境,可是花了一番的功夫,
因为redhat linux 9.0 默认的perl版本下,安装以上的module总是不成功,
最后仔细琢磨了一番,终于安装好了两个必要的module.大体步骤如下:
1.1安装perl5.8.8
#wget http://search.cpan.org/CPAN/authors/id/N/NW/NWCLARK/perl-5.8.8.tar.gz
#tar -zxvf perl-5.8.8.tar.gz
然后进入perl-5.8.8的目录,去读INSTALL,安装好新的perl
1.2安装必要的module
#perl -MCPAN -e shell
初始化配置参考http://www.omakase.org/perl_module.htm
常用module安装(可选)
cpan> install XML::XPath
cpan> install SOAP::Lite
cpan> install Jcode
cpan> install DB_File
cpan> install DBI
cpan> install DBD::mysql
cpan> install Bundle::LWP
cpan> install Bundle::CPAN
cpan> install CGI
cpan> install HTML::Entities
cpan> install Mail::Internet
cpan> install Pod::Text
cpan> install Bundle::XML
虽然可能在这里面的操作中,会出现error但是,毕竟装了不少,对以后安装会有好处的。
本功能必备安装(如果上面常用安装已经执行过了,这一步,只是起到确认左右)
cpan> install XML::RSS
从新挂载cpan服务
cpan> reload cpan
2.相关rss文件 和 perl 相关model 简单介绍
2.1 rss文件
在这里就是简单的介绍一下主要的几条语言,首先是要了解,几个常用的大网站提供的rss的结构,
我就不多说了,自己看看就可以了,如果对于XML文档结构不是很了解,去w3c school补补课吧。
这里仅仅给出相关的几个rss文件的地址,提供下载研究:
yahoo news : http://rss.news.yahoo.com/rss/topstories (经测试,本代码中应用成功)
csdn personal blog : http://blog.csdn.net/thefirstwind/Rss.aspx (经测试,本代码中应用成功)
2.2 LWP::Simple 和 XML::RSS 组合模块代码1










2.3LWP::Simple 和 XML::RSS 组合模块代码2










以上两种方法都可以,从现在开始$rss存有rss/xml文件的所有信息了,以后对其下面的节点,直接->{'节点名'},
如此引用就可以了。
3 代码实例
好了说了那么多废话,终于要看看代码了。






























































































关于代码下载去
http://thefirstwind.ddo.jp/~devuser/cgi-bin/
rss文件是源rss的拷贝生成版本。
pl是执行代码。
txt是用来在web上显示的pl代码。
最后一句废话,版权所有,转载请申明出处。
本文地址:http://www.45fan.com/dnjc/68894.html