PHP 抓取跳转后的url --爬虫

这个链接 http://sbdp.baidudaquan.com/down.asp?id=77664085&token=9c09e86abbc5827210815c1fd54a1df4

 

复制到浏览器中自动回跳转到新的url

我希望通过php代码得到跳转后的url。

折磨好几个小时 终于搞定了代码如下

function curl_get($url)
{
    $ch=curl_init();
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch,CURLOPT_HEADER,1);
    $result=curl_exec($ch);
    $code=curl_getinfo($ch,CURLINFO_HTTP_CODE);
    if($code!='404' && $result)
    {
        return $result;
    }
    curl_close($ch);
}
$content = curl_get("http://sbdp.baidudaquan.com/down.asp?id=77664085&token=9c09e86abbc5827210815c1fd54a1df4");

echo $content;

 

 

content

HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 362
Content-Type: text/html
Server: Microsoft-IIS/7.5
Set-Cookie: ASPSESSIONIDACATADCT=PNNGOBACNBNABPJBKGFBDGFE; path=/
X-Powered-By: ASP.NET
Date: Fri, 03 Feb 2017 10:26:13 GMT


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<div style="margin:0 auto;margin-top:10%;width:600px;border: 1px solid #ff0000;line-height:30px;padding:10px 10px 10px 10px; ">提示:亲,正在为您跳转,请稍等2秒..... <meta http-equiv='refresh' content='2;URL=http://pan.baidu.com/share/link?shareid=3110667424&uk=507450286'></div>

 

看到上面代码恍然大悟 原来如此 大学就学这个。我怎么没想到他是这么设计的。

下面是网上的方法 我试了一下不行啊。

$url = 'http://t.cn/h5mwx';
$headers = get_headers($url, TRUE);

 

print_r($headers);

//输出跳转到的网址
echo $headers['Location'];

posted on 2017-02-03 18:28  php超超  阅读(3753)  评论(0编辑  收藏  举报