PHP 抓取html页面内容 函数
2014-11-12 18:40
309 查看
function getHtml($url,$id=0){
$file_path = ATTACHEMENT_PATH.'caiji/';
if ($id) {
$file_path.=($id%10).'/';
}
if (!is_dir($file_path)) {
mkdir($file_path,0777,true);
}
$fname = md5(trim($url));
$file = $file_path.$fname.'.txt';
$string = file_get_contents($file);
if (!$string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$string = curl_exec($ch);
file_put_contents($file, $string);
}
return $string ;
}
$file_path = ATTACHEMENT_PATH.'caiji/';
if ($id) {
$file_path.=($id%10).'/';
}
if (!is_dir($file_path)) {
mkdir($file_path,0777,true);
}
$fname = md5(trim($url));
$file = $file_path.$fname.'.txt';
$string = file_get_contents($file);
if (!$string) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
$string = curl_exec($ch);
file_put_contents($file, $string);
}
return $string ;
}
相关文章推荐
- 简单的PHP伪缓存并定时抓取某页面内容
- php获取网页标题和内容函数(不包含html标签)
- Nodejs抓取html页面内容(推荐)
- php--正则匹配抓取html的相关内容
- PHP使用DomDocument抓取HTML内容
- curl,fsocketopen,socket 三种函数抓取html页面
- php利用simple_html_dom类,获取页面内容,充当爬虫角色
- [HTML/JS]利用JQuery的load函数动态加载其它页面的内容的实现代码代替Ifram
- php获取网页标题和内容函数(不包含html标签)
- 【HTML/JS】利用JQuery的load函数动态加载其它页面的内容的实现代码
- php读取外部txt文件内容并打印在页面|fopen()函数
- php利用simple_html_dom类,获取页面内容,充当爬虫角色
- php获取网页标题和内容函数(不包含html标签)
- php抓取页面simple_html_dom的使用教程
- php获取网页标题和内容函数(不包含html标签)
- JaveScript 初级知识,简称Js。与HTML的css相似,不过css只控制标签,而JS可以控制页面内容。相类似函数调用
- 小随笔——PHP清空页面内容、在html中嵌套使用
- php抓取网站内容,获取通达OA官网最新用户,判断页面是否能访问,php正则
- 使用phpQuery 抓取HTML 页面内容
- 一个PHP页面抓取函数