我正在执行一个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);
?>
感谢您的支持......修正了代码......为什么它不为某些网站返回,而是为了其他网站? – onei0120
您是否尝试过使用普通桌面用户代理?如果工程,然后他们正在筛选您的请求 – Maks3w
只用一个正常的用户代理字符串尝试,仍然没有工作,没有卷曲错误 – onei0120