Home  >  Article  >  Backend Development  >  CSDN论坛RSS阅读,(新手学采集,原创),谢谢指教。

CSDN论坛RSS阅读,(新手学采集,原创),谢谢指教。

WBOY
WBOYOriginal
2016-06-23 14:25:04938browse

情况是这样的:CSDN论坛,没有手机版,也没有平板电脑版;其他有几位好汉,自行设计了一个addroid系统上的安装版,也有其不好之处:一定要安装(占空间占内存)而且没法自定义自己喜欢的版块。

我个人喜欢在公交车上看点东西,晚上也喜欢在床上访问csdn论坛,为了学习嘛没办法。若直接打开www.csdn.net 我的流量怎么办呢?加载时间很长且错版,全是广告、图片。今天自己写了一个可以阅读csdn rss的程序,为了学习采集与xml吧,与共好汉分享一番。如下

程序名:csdn论坛阅读(手机,平板电脑专用)

演示地址: http://www.ruci.org/rss.php

原理:php读csdn的rss,再采集论坛中各用户的发言。

特点:适合在手机、平板电脑、pda移动终端上访问论坛,无多余图片,无广告,可自定义自己喜欢的版块,加载速度快,流量少,免安装之特点。
请高手指点一番,不妥之处,谢谢。
rss.php

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>CSDN论坛RSS阅读</title></head><body><h3>CSDN论坛RSS阅读,平板电脑专用</h3><ul><li><a href="show.php?t=ModeratorRecommendTech&m=c">版主推荐-技术区</a></li><li><a href="show.php?t=ModeratorRecommendLife&m=c">版主推荐-生活区</a></li><br><li><a href="show.php?t=WebDevelop">Web 开发</a></li><li><a href="show.php?t=PHP">PHP</a></li><li><a href="show.php?t=HTMLCSS">Web 开发 HTML(CSS)</a></li><li><a href="show.php?t=JavaScript">Web 开发 JavaScript</a></li><li><a href="show.php?t=MySQLPostgresql">其他数据库开发 MySQL/Postgresql</a></li><br><li><a href="show.php?t=Linux">Linux/Unix社区</a></li></ul></body></html>

show.php
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>csdn在线浏览器</title></head><body><p><a href="rss.php">返回</a></p><?phpif($_GET['m']){	$rss_link="http://bbs.csdn.net/ASCX/NewHomePage/ModeratorRecommend/".$_GET['t'].".xml";//定义远程RSS链接	}else{	$rss_link="http://forum.csdn.net/Rss/".$_GET['t']."/UnClosedList/";//定义远程RSS链接	}		$dom=new DOMDocument();//创建DOM对象	$dom->load($rss_link);//读取xml文件	$rss_root=$dom->documentElement;//获取xml数据的根	$items=$rss_root->getElementsByTagName("item");//获得所有的item节点	foreach($items as $it){//读取第一个item节点		$children=$it->childNodes;//获取$it的所有节点;		$row_array=array();//初始化数组			foreach($children as $key=>$e)//处理每一个item				{				if((strcmp($e->nodeName,"title")==0))//获得每个item的title和link					{						$row_array[$e->nodeName]="*".$e->nodeValue;					}					if((strcmp($e->nodeName,"link")==0))					{						$row_array[$e->nodeName]="<a href='showContent.php?t=".$e->nodeValue."'>Read</a>";						}				}				$row=implode("=>",$row_array);//将读取的数据保存到字符串中				$row.="<br>";				echo $row;		}?></body></html>

showContent.php
<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>无标题文档</title></head><body><p><a href="javascript:history.back()">返回</a></p><?php$url=$_GET['t'];//$url="http://topic.csdn.net/u/20120315/21/55ed47df-9ae2-4958-8446-5f659415c743.html";$con= file_get_contents($url);function getUrl($url){$url=substr($url,36,36);return $url;}$preg='#<div class="msgfont">(.*)<\/div>#iUs';$preg2='#\(this,111\);\'>(.*)<\/a><\/dfn><\/li>#U';preg_match_all($preg, $con, $arr);preg_match_all($preg2, $con, $arr2);for($i=0;$i<count($arr[1]);$i++){	echo "";	if($i==0){		echo "楼主".$arr2[1][$i].":".$arr[1][$i].'<br>';		}	else{		echo "第".$i."楼".$arr2[1][$i].":".$arr[1][$i].'<br>';		}	}?></body></html>


回复讨论(解决方案)

支持原创分享,用SimpleXML代码估计能再少点,xml处理我做得不多,多数时候都是用json
这帖我来结.

牛人!

一般订了rss的种,有新的消息,都会向客户端推送的,这就是rss

那个传地址,没处理好。

真是牛人一个啊  

演示地址打不开

dom操作。。。。我以为只有js才能做dom操作呢,丢人了啊。

good and helpful.            

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn