我正在执行一个 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);
?>