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'];


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM