查看完整版本: 也谈截取首页新闻 - 范例

lily 2007-8-1 22:16

也谈截取首页新闻 - 范例

             <p><span class="t18">截取yahoo.com.cn新闻[仅供实验] <br><br>有很多截取首页新闻的程序,但是并不能成功。 <br>他们的<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%B9%A4%D7%F7');" target="_self"><u><strong>工作</strong></u></a>原理无非两种,一种是采用某些网站称之为backend的后端<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%CA%FD%BE%DD%BF%E2');" target="_self"><u><strong>数据库</strong></u></a>接口,另一种则是硬声声的根据html代码截取。本程序采用的是后者。应该说,容错性能比较好。 <br>&lt;? <br>$open = fopen("http://www.yahoo.com.cn/index.html", "r");//网页地址 <br>$read = fread($open, 15000); <br>fclose($open); <br><br>$search = eregi("&lt;!-- Start in the news --&gt;(.*)&lt;!-- End in the news --&gt;", $read, $printing);//截取一段源<a href="http://www.phpchina.com/javascript:;" onClick="javascript:tagshow(event, '%B4%FA%C2%EB');" target="_self"><u><strong>代码</strong></u></a>,最好先分析一下源代码 <br>//以下开始取出容余源代码 <br>$printing[1] = str_replace("href=http://www.phpchina.com/\"/homer/?", "href=http://www.phpchina.com/\"", $printing[1]); <br>$printing[1] = str_replace("href=http://www.phpchina.com/\"/headlines/fullcoverage/", "href=http://www.phpchina.com/\"http://www.yahoo.com.cn/headlines/fullcoverage/", $printing[1]); <br>$printing[1] = str_replace("&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td valign=top align=right&gt;", "", $printing[1]); <br>$printing[1] = str_replace("&lt;/td&gt;&lt;td&gt;", "", $printing[1]); <br>$printing[1] = str_replace(" class=sbody", "", $printing[1]); <br>$printing[1] = str_replace("&lt;/small&gt;", "", $printing[1]); <br><br>$content = $printing[1]; <br>$content = explode("-", $content); <br><br>$headlines = sizeof($content); <br><br>for ($i = 0; $i &lt; $headlines; $i++) { <br><br>print "新闻".($i+1).") : $content[$i]&lt;BR&gt;";//激动人心的时刻到了!显示出来了! <br><br>} <br><br>?&gt; <br></span><div>
页: [1]
查看完整版本: 也谈截取首页新闻 - 范例
PageRank