《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;}
public static function curlContent($url, $encode = true) { //不走缓存 $content = Request::curl($url); if (empty($content)) { sleep(1); $content = Request::curl($url); } $encode && $content = iconv("GBK", "UTF-8//IGNORE",$content); return $content; }
维易PHP培训学院每天教你实战技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培养人才。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/6682.html