php抓捕网页内容的几种方式

$handle = fopen ("http://www.example.com/", "rb");
$contents = "";
do {
   $data = fread($handle, 8192);
   if (strlen($data) == 0) {
   break;
   }
   $contents .= $data;
} while(true);
fclose ($handle);

2.file_get_contents

$url = "http://www.example.com/";
$contents = file_get_contents($url);
/***如果出现中文乱码使用下面代码***/
$getcontent = iconv("gb2312", "utf-8",file_get_contents($url));

3.curl

$url = "http://www.example.com/";
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
/***在需要用户检测的网页里需要增加下面两行***/
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, US_NAME.":".US_PWD);

4.ob_get_contents获取本地php网页内容

session_start();
ob_start();
include('test.php');
contents = ob_get_contents();
$contents = curl_exec($ch);
curl_close($ch);

标签: 抓捕方式网页
------分隔线----------------------------
· 首页 · 注册

百鸣[Baiming.org]欢迎您 百鸣[Baiming.org]欢迎您~