- PHP code
$ghurl = isset($_GET['id']) ? $_GET['id']:'http://3gabc.com/';
// php 获取
function getContents($url){
$header = array("Referer: http://3gabc.com/");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1); //是否抓取跳转后的页面
ob_start();
curl_exec($ch);
$contents = ob_get_contents();
ob_end_clean();
curl_close($ch);
return $contents;
}
$contents = getContents($ghurl);
echo $contents;
?>
失败。。。
- PHP code
失败。。。
先后 尝试fsockopen/curl等方法,获取header并判断执行,但都失败,请教各位。
------解决方案--------------------
3gabc.com就只有这么一句。
你也只能获取到这个,meta refresh是在浏览器上执行的!!!
------解决方案--------------------
因为3gabc.com就只有这么一句。
你在抓取页面后 “echo $contents;” 页面自然就重定向到http://www.3Gabc.com 了。
所以不能echo $contents; 而是用正则“preg_match("//is",$content, $matches)”
抓出转向地址,然后在curl这个转线地址,就可以抓到你要的内容了。