亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP 采集獲取指定網(wǎng)址的內(nèi)容

 更新時(shí)間:2010年01月05日 23:00:37   作者:  
用php來(lái)獲取指定網(wǎng)頁(yè)內(nèi)容的實(shí)現(xiàn)代碼,一般采集程序經(jīng)常用的一些代碼,這里只是一個(gè)簡(jiǎn)單的基礎(chǔ)。更詳細(xì)的資料可以參考php 采集成品,可以使用的源碼,這樣才能學(xué)會(huì)更多的東西。
參考別人想法變成自己的想法,你會(huì)發(fā)現(xiàn)慢慢下來(lái)以后你就擁有了臨時(shí)解決很多問(wèn)題的思路與方法。
復(fù)制代碼 代碼如下:

<?php
/*
功能:獲取頁(yè)面內(nèi)容,存儲(chǔ)下來(lái)閱讀; lost63
*/
Class GetUrl{
var $url; //地址
var $result; //結(jié)果
var $content; //內(nèi)容
var $list; //列表
function GetUrl($url){
$this->url=$url;
$this->GetContent();
$this->GetList();
$this->FileSave();
//print_r($this->list[2]);
}
private function GetContent(){
$this->result=fopen($this->url,"r");
while(!feof($this->result)){
$this->content.=fgets($this->result,9999);
}
}
private function GetList(){
preg_match_all('/<a(.*?)href="(.*?)">(.*?)<\/a>/',$this->content,$this->list);
$this->list[2]=array_unique($this->list[2]); //移除相同的值
while(list($key,$value)=each($this->list[2])){
if(strpos($value,".html")==0||strpos($value,"jiaocheng")==0){
unset($this->list[2][$key]);
}else{
$this->list[2][$key]=substr($value,0,strpos($value,".html")).".html"; //去掉不需要的標(biāo)簽
}
}
}
private function FileSave(){
foreach($this->list[2] as $value){
$this->url=$value; //重新賦值
$this->content=null;
$this->GetContent(); //提取內(nèi)容
preg_match_all('/<title>(.*?)<\/title>/',$this->content,$files); //取標(biāo)題
$filename=$files[1][0].".html"; //存儲(chǔ)名
$content=$this->str_cut($this->content,'http://pagead2.googlesyndication.com/pagead/show_ads.js','<div id="article_detail">');
$file=fopen($filename,"w");
fwrite($file,$content);
fclose($file);
echo $filename."保存 OK<br>\n";
}
}
function str_cut($str ,$start, $end) {
$content = strstr( $str, $start );
$content = substr( $content, strlen( $start ), strpos( $content, $end ) - strlen( $start ) );
return $content;
}
}
$w=new GetUrl("http://www.ijavascript.cn/jiaocheng/javascript-jiaocheng-352.html");
?>

相關(guān)文章

最新評(píng)論