欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP 采集获取指定网址的内容_php技巧

程序员文章站 2023-12-30 13:17:04
...
参考别人想法变成自己的想法,你会发现慢慢下来以后你就拥有了临时解决很多问题的思路与方法。
复制代码 代码如下:

/*
功能:获取页面内容,存储下来阅读; lost63
*/
Class GetUrl{
var $url; //地址
var $result; //结果
var $content; //内容
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('/(.*?)/',$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"; //去掉不需要的标签
}
}
}
private function FileSave(){
foreach($this->list[2] as $value){
$this->url=$value; //重新赋值
$this->content=null;
$this->GetContent(); //提取内容
preg_match_all('/(.*?)/',$this->content,$files); //取标题 <br>$filename=$files[1][0].".html"; //存储名 <br>$content=$this->str_cut($this->content,'http://pagead2.googlesyndication.com/pagead/show_ads.js','<div id="article_detail">'); <br>$file=fopen($filename,"w"); <br>fwrite($file,$content); <br>fclose($file); <br>echo $filename."保存 OK<br>\n"; <br>} <br>} <br>function str_cut($str ,$start, $end) { <br>$content = strstr( $str, $start ); <br>$content = substr( $content, strlen( $start ), strpos( $content, $end ) - strlen( $start ) ); <br>return $content; <br>} <br>} <br>$w=new GetUrl("http://www.ijavascript.cn/jiaocheng/javascript-jiaocheng-352.html"); <br>?><br> </div> <a href="/default/index/url?u=aHR0cHM6Ly93d3cucGhwLmNuL2suaHRtbD90PTI=" target="_blank" rel="nofollow"><img onerror="this.src='/statics/superweb999/images/image_error.jpg'"src="/default/index/img?u=aHR0cHM6Ly9pbWcucGhwLmNuL3VwbG9hZC9jb3Vyc2UvMDAwLzAwMC8wNzEvNjIwYzYwNGY3NTI1MTk5NS5wbmc=" style="margin-top: 30px;" alt="PHP 采集获取指定网址的内容_php技巧" title="PHP 采集获取指定网址的内容_php技巧"></a><p style="float:right;font-size:13px;color:#999;"><span class="red">声明:</span>本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。</p>

相关文章

相关视频


相关标签: PHP 采集

上一篇:

下一篇: