开州企业网站建设-用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 , UTF-8//IGNORE ,$content);
 return $content;
---------

开州企业网站建设

------------

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://zmjldkxcx.cn/jingyan/3176.html