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

参考别人想法变成自己的想法,你会发现慢慢下来以后你就拥有了临时解决很多问题的思路与方法。
<div class="codetitle"><a style="CURSOR: pointer" data="33486" class="copybut" id="copybut33486" onclick="doCopy('code33486')"> 代码如下:

<div class="codebody" id="code33486">
<?php
/
功能:获取页面内容,存储下来阅读; 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('/<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,strpos($value,".html")).".html"; //去掉不需要的标签
}
}
}
private function FileSave(){
foreach($this->list[2] as $value){
$this->url=$value; //重新赋值
$this->content=null;
$this->GetContent(); //提取内容
preg_match_all('/(.</em>?)<\/title>/',$files); //取标题 <BR>$filename=$files[1][0].".html"; //存储名 <BR>$content=$this->str_cut($this->content,'<a href="http://pagead2.googlesyndication.com/pagead/show_ads.js">http://pagead2.googlesyndication.com/pagead/show_ads.js</a>','<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("<a href="http://www.ijavascript.cn/jiaocheng/javascript-jiaocheng-352.html">http://www.ijavascript.cn/jiaocheng/javascript-jiaocheng-352.html</a>"); <BR>?><BR></div></p><!-- jb51-mobi-auto-h --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4605373693034661" data-ad-slot="1811740773" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> <div class="topcard-tags"></div> </div> </div> </div> <!-- row end--> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <!-- jb51-mobi-auto-h --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4605373693034661" data-ad-slot="1811740773" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="clearfix"></div> <!-- row --> <div class="col-sm-12 col-md-12 col-lg-12"> <div class="card"> <div class="title"><h1>相关文章</h1></div><div class="list_con"> <div class="title"> <a href="/php/4739043.html" title="vue+thinkphp5实现微信扫码支付(NATIVE支付)">vue+thinkphp5实现微信扫码支付(NATIVE支付)</a> </div> <div class="summary">统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...</div> </div><div class="list_con"> <img src="/res/2024/07-30/10/32d06eca1830b39e35547ff639b7b95b.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="/php/4739042.html" title="uniapp+thinkphp5实现微信扫码支付(APP支付)">uniapp+thinkphp5实现微信扫码支付(APP支付)</a> </div> <div class="summary">统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...</div> </div><div class="list_con"> <img src="/res/2024/07-30/10/3d907355e295604aef536bba5b45dd7d.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="/php/4739041.html" title="uniapp+thinkphp5实现微信登录">uniapp+thinkphp5实现微信登录</a> </div> <div class="summary">前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...</div> </div><div class="list_con"> <img src="/res/2024/07-30/10/fc29e4e4eba385bc042444571f518ef6.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="/php/4739040.html" title="【PHP】关于fastadmin框架中使用with进行连表查询时setEagerlyType字段的理解">【PHP】关于fastadmin框架中使用with进行连表查询时setEagerlyType字段的理解</a> </div> <div class="summary">FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...</div> </div><div class="list_con"> <img src="/res/2024/07-30/10/e6971fb86d3ee30a4466e87826da43d8.png" width="100" height="64" style="float:right;margin-left:20px;" /> <div class="title"> <a href="/php/4739039.html" title="【workerman】uniapp+thinkPHP5使用GatewayWorker实现实时通讯">【workerman】uniapp+thinkPHP5使用GatewayWorker实现实时通讯</a> </div> <div class="summary">之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...</div> </div><div class="list_con"> <div class="title"> <a href="/php/4739038.html" title="uniapp+thinkphp5实现微信支付(JSAPI支付)">uniapp+thinkphp5实现微信支付(JSAPI支付)</a> </div> <div class="summary">统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...</div> </div><!-- jb51-mobi-auto-h --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-4605373693034661" data-ad-slot="1811740773" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <!-- row end--> </div> </div> <footer id="footer"> <div class="container"> <div class="copyright"> Copyright © 2018 编程之家. 当前版本 V7.0.16<br> <span class="ml5">编程之家 版权所有 <a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">闽ICP备13020303号-8</a> </div> </div> </footer> <script src="/js/count.js"></script> </body> </html>