php fsockopen/curl如何获取目标转向后的页面代码问题
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这个转线地址,就可以抓到你要的内容了。