php抓取网页代码四种方法
2010-09-09 20:52
666 查看
PHP抓取页面代码四种 方法: 1. file()函数 2. file_get_contents()函数 3. fopen()->fread()->fclose()模式 4.curl方式 file()方法: <?php $url='http://t.qq.com'; $lines_array=file($url); $lines_string=implode('',$lines_array); echo htmlspecialchars($lines_string); ?> file_get_contents()方法: <?php $url='http://t.qq.com'; $lines_string=file_get_contents($url); echo htmlspecialchars($lines_string); ?> fopen()->fread()->fclose()模式 <?php $url='http://t.qq.com'; $handle=fopen($url,"rb"); $lines_string=""; do{ $data=fread($handle,1024); if(strlen($data)==0){break;} $lines_string.=$data; }while(true); fclose($handle); echo htmlspecialchars($lines_string); ?> CURL方法: <?php $url='http://t.qq.com'; $ch=curl_init(); $timeout=5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $lines_string=curl_exec($ch); curl_close($ch); echo htmlspecialchars($lines_string); ?>
相关文章推荐
- PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
- PHP网页抓取之抓取百度贴吧邮箱数据代码分享
- php抓取网页内容方法分析
- PHP抓取及分析网页的方法详解
- PHP抓取网页内容的方法
- PHP抓取网页、解析HTML常用的方法总结
- 使用php方法curl抓取AJAX异步内容思路分析及代码分享
- 几种PHP实现网页抓取的程序代码
- PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
- 几种PHP实现网页抓取的程序代码
- PHP抓取网页内容的方法
- php获得网页源代码抓取网页内容的几种方法
- PHP 抓取网页图片并且另存为的实现代码
- 【转】用php抓取网页内容方法总结
- 用php抓取网页内容方法总结
- PHP的CURL方法curl_setopt()函数案例介绍(抓取网页,POST数据)
- PHP中使用file_get_contents抓取网页中文乱码问题解决方法
- php如何抓取网页中邮箱地址代码
- 分享PHP源码批量抓取远程网页图片并保存到本地的实现方法