2010-02-09 89 views
1

實施例:http://www.whois.net/whois/hotmail.comPHP中使用CURL抓住WHOIS記錄

當瀏覽器中打開,示出了輸出。

使用捲曲調用時,它什麼都不顯示。

怎麼了?我想返回整個頁面結果,然後使用正則表達式在截止日期:29-Mar-2015 00:00:00行檢索數據。

$postfields= null; 
$postfields["noneed"] = ""; 
$queryurl= "http://www.whois.net/whois/hotmail.com"; 

$results= getUrlContent($postfields, $queryurl); 
echo $results; 


function getUrlContent($postfields,$api_url) 
{ 
    if(!extension_loaded('curl')){die('You need to load/activate the cURL extension (http://www.php.net/cURL).'); } 

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $api_url); // set the url to fetch 
    curl_setopt($ch, CURLOPT_HEADER, 0); // set headers (0 = no headers in result) 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // type of transfer (1 = to string) 
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); // time to wait in seconds 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
    $content = curl_exec($ch); // make the call 
    curl_close($ch); 
    return $content; 
} 
+0

什麼是在這個問題上與正則表達式? – 2010-02-09 04:06:43

+0

刪除了正則表達式引用。他們可能希望在從CURL獲得結果後使用正則表達式,這可以通過我最後的評論來避免。 – Anthony 2010-02-09 04:12:53

+0

請確保您閱讀 - http://www.whois.net/terms-and-conditions,尤其是以下部分:您無權訪問或查詢WHOIS.NET系統,通過 使用電子程序,量和自動 除非合理必要註冊域名或修改現有註冊。 – 2011-08-09 20:12:37

回答

3

Whois.net檢查user agent。因此,這些添加到你的函數調用curl_exec

$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
0

之前,你看到的錯誤是不相關的whois.com,就說明你沒有啓用捲曲模塊爲PHP。先嚐試啓用PHP cURL模塊。

關注這個線程,如果你不知道如何啓用PHP捲曲模塊:How to enable cURL in PHP/XAMPP

希裏什