2016-08-12 4 views
1
私はこのウェブサイトのためのカールとの最後の効果的なURLを取得する必要があり

を取得effective_url`not: http://www.wechat.com/en/ 私が使用している場合、カールのcurl_getinfo($curl, CURLINFO_EFFECTIVE_URL);私はhttp://www.wechat.com/を得るが、あなたがサイトを訪問する場合は、URLを見ることができます最後に/ en /を追加することによって変更されます。カールは `最後の効果的なURL

コード:

$url = 'http://www.wechat.com'; 
$curl = curl_init($url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt ($curl,CURLOPT_VERBOSE, false); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); 
curl_setopt($curl, CURLOPT_TIMEOUT, 5); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 
$ip = curl_getinfo($curl, CURLINFO_PRIMARY_IP); 
$last_effective_url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); 
curl_close($curl); 

echo $last_effective_url; 

私はここに私の心のうちつもりです。ヘルプをいただければ幸いです。

答えて

0

ここでの問題は、CURLが解釈できるURLの/en/ URLへのHTTPリダイレクトコードがないことです。 CURLはHTTP200を見てそこで停止します。

代わりに、CURLで解釈できないブラウザのJavascriptによってページがリフレッシュされます。

したがって、CURLの有効なURLは「http://www.wechat.com」であり、これは正しい動作です。アクションではJavaScriptを参照するには:ページhttp://www.wechat.com/(ブラウザでhttp://www.wechat.com/index.htmlビューソース):のソースで

ルック

<script> 
     (function() { 
      Array.prototype.contain = function (f) { 
       var e = this.length; 
       while (e--) { 
        if (this[e] === f) { 
         return true 
        } 
       } 
       return false 
      }; 
      var c = ["en", "zh", "pt", "th", "vi", "id", "es", "ru", "ar", "he", "pl", "hi", "ja", "it", "ko", "ms", "tr"], a = navigator.language || navigator.userLanguage || 'en', a = a.replace(/-\w+/, ""), d = location.pathname.match(/\/(\w+)\/(\w*)/i), b = c.contain(a) ? a : "en", b = b == "zh" ? "zh_TW" : b; 
      if (location.pathname == "/index.html" || location.pathname == "/" || location.pathname == "/cgi-bin/readtemplate") { 
       location.href = location.protocol + "//" + location.host + "/" + b + "/"; 
       return 
      } 
      if (d && d[1]) { 
       return 
      } 
      location.href = location.href.replace(/\w+\/(\w+)\//i, function (e, f) { 
       return e.replace(f, b) 
      }) 
     })(); 
    </script> 
+0

ああ、私はそれを指摘して感謝を参照してください。私はまだそれを取得する必要がありますが、それはカールのような終わりのようです。 –

+0

答えを受け入れることができますか?ありがとう! – Cagy79

関連する問題