[PHP] 纯文本查看 复制代码
<?php
$page=1;
//取文本中间的函数
function getSubstr($str, $leftStr, $rightStr)
{
$left = strpos($str, $leftStr);
//echo '左边:'.$left;
$right = strpos($str, $rightStr,$left);
//echo '<br>右边:'.$right;
if($left < 0 or $right < $left) return '';
return substr($str, $left + strlen($leftStr), $right-$left-strlen($leftStr));
}
//取文本右边的函数
function getSubstrRight($str, $leftStr)
{
$left = strpos($str, $leftStr);
//echo '左边:'.$left;
if($left < 0 ) return '';
return substr($str, $left + strlen($leftStr));
}
function caiji_waa($currpage){
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, 'http://yaxige.waa.cn/');
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 1);
//获取请求头
curl_setopt($curl, CURLINFO_HEADER_OUT, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_NOBODY, 1);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36');
//curl_setopt($curl, CURLOPT_POST, 0);
//执行命令
$data = curl_exec($curl);
//echo $data;
//print_r($_SERVER);
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
// 根据头大小去获取头信息内容
$header = substr($data, 0, $headerSize);
//print_r($header);
$cookie='shop_json='.getSubstr($header , "shop_json=", ';').";";
echo $cookie;
//print_r(curl_getinfo($curl));
//关闭URL请求
curl_close($curl);
//显示获得的数据
//print_r($header);
//echo $cookie;
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, 'http://yaxige.waa.cn/home/index/index_do');
//设置头文件的信息作为数据流输出
//curl_setopt($curl, CURLOPT_HEADER, 1);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//设置post提交cookies
curl_setopt($curl,CURLOPT_COOKIE,$cookies);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
//设置post数据
$post_data = "";
//post提交的数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
//执行命令
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl);
//显示获得的数据
//print_r(curl_getinfo($curl));
//echo $data;
print_r($data);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>欢迎您!</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"> </script>
</head>
<body>
<?php caiji_waa($page); ?>
</body>
</html>