微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php抓取程序逻辑代码

PHP抓取程序逻辑代码》要点:
本文介绍了PHP抓取程序逻辑代码,希望对您有用。如果有疑问,可以联系我们。

  • 带缓存的抓取逻辑
    public static function crawlContent($url,$encode = true) { $file_name = '../cache/'.md5($url); if (!file_exists($file_name)) { @touch($file_name); } $content = file_get_contents($file_name); if (empty($content)) { $content = Request::curl($url); if (empty($content)) { sleep(1); $content = Request::curl($url); } $encode && $content = iconv("GBK","UTF-8//IGnorE",$content); file_put_contents($file_name,$content); } return $content;}
  • 不带缓存,直接curl数据
     public static function curlContent($url,$encode = true) { //不走缓存 $content = Request::curl($url); if (empty($content)) { sleep(1); $content = Request::curl($url); } $encode && $content = iconv("GBK",$content); return $content; }

编程之家PHP培训学院每天教你实战技能,PHPMysqL、LINUX、APP、JS,CSS全面培养人才。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐