2012-09-14 61 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