2012-09-14 62 views
0

我正在執行一個cURL請求,並且大多數情況下它可以工作,但對於某些網站它什麼也沒帶回,並且cURL沒有錯誤。任何人都可以給我一些幫助嗎?cURL不爲某些網站返回任何東西

這裏是我的小應用程序:http://www.convurgency.com/tools/googlebot.php

去那裏,在這個網站上輸入:http://www.beemak.com

正如你可以看到很多網站的工作,但選擇的不...任何想法?

這裏是我的代碼:

<?php 
//Bot Curl Request 


$handle = curl_init(); 

curl_setopt_array($handle,array(
     CURLOPT_URL => $_GET['site'], 
     CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', 
     CURLOPT_RETURNTRANSFER => true, 
     CURLOPT_FOLLOWLOCATION => true 
    )); 

    $output = curl_exec($handle); 

    $httpcode = curl_getinfo($handle, CURLINFO_TOTAL_TIME); 
    $connecttime = curl_getinfo($handle, CURLINFO_CONNECT_TIME); 
    $downloadtime = curl_getinfo($handle, CURLINFO_SPEED_DOWNLOAD); 
    $downloadsize = curl_getinfo($handle, CURLINFO_SIZE_DOWNLOAD); 

    if(curl_errno($handle)){ 
     echo '<img class="errorlogo" src="http://www.convurgency.com/images/logo103.png" />'; 
     echo '<p style="text-align:center;">There was an error finding your site, are you sure it exists?</p>'; 
     echo '<p style="text-align:center;"><a href="http://www.convurgency.com/tools/googlebot.php">Back to GoogleBot View</a></p>'; 
     echo 'Curl error: ' . curl_error($handle); 

    } else { 

     echo 'No Errors'; 

    }; 

    if (curl_error($handle)) { 
    print "ERROR ". curl_error($handle) ."\n<br/>"; 
    } 


    curl_close($handle); 


    $output2 = preg_replace(
     array(
     // Remove invisible content 
     '@<head[^>]*?>.*?</head>@siu', 
     '@<style[^>]*?>.*?</style>@siu', 
     '@<script[^>]*?.*?</script>@siu', 
     '@<object[^>]*?.*?</object>@siu', 
     '@<embed[^>]*?.*?</embed>@siu', 
     '@<applet[^>]*?.*?</applet>@siu', 
     '@<noframes[^>]*?.*?</noframes>@siu', 
     '@<noscript[^>]*?.*?</noscript>@siu', 
     '@<noembed[^>]*?.*?</noembed>@siu', 
     // Add line breaks before and after blocks 
     '@</?((address)|(blockquote)|(center)|(del))@iu', 
     '@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu', 
     '@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu', 
     '@</?((table)|(th)|(td)|(caption))@iu', 
     '@</?((form)|(button)|(fieldset)|(legend)|(input))@iu', 
     '@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu', 
     '@</?((frameset)|(frame)|(iframe))@iu', 
     ), 
        array(' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",), $output); 

echo preg_replace('/<(\w+) [^>]+>/', '<$1>', $output2); 

?> 
+0

感謝您的支持......修正了代碼......爲什麼它不爲某些網站返回,而是爲了其他網站? – onei0120

+0

您是否嘗試過使用普通桌面用戶代理?如果工程,然後他們正在篩選您的請求 – Maks3w

+0

只用一個正常的用戶代理字符串嘗試,仍然沒有工作,沒有捲曲錯誤 – onei0120

回答

0

看$ connecttime和$ downloadtime並檢查是否請求沒有超時。檢查您是否可以使用命令行curl或wget從運行腳本的服務器訪問該網站。

+0

不是請求不會超時,它會將完整的下載大小和下載時間返回給我 – onei0120