php使用CURL抓取whois记录
示例: http://www.whois.net/whois/hotmail.com
何时在浏览器中打开,显示输出。
当使用curl调用时,它什么也不显示。
怎么了?我想返回整个页面结果,然后使用正则表达式检索 Expiration Date: 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;
}
Example: http://www.whois.net/whois/hotmail.com
When open in browser, output is shown.
When using curl call, it show nothing.
What's wrong? I want to return whole page result, then use regular expression to retrieve data at Expiration Date: 29-Mar-2015 00:00:00 line.
$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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Whois.net 检查
用户代理
。因此,在调用curl_exec之前将这些添加到您的函数中Whois.net checks
user agent
. So add these to your function before you callcurl_exec
您看到的错误与 whois.com 无关,它表明您尚未为 PHP 启用 cURL 模块。首先尝试启用 PHP cURL 模块。
如果您不确定如何启用 PHP cURL 模块,请按照此主题操作:如何启用PHP / XAMPP 中的 cURL
Shirish
The error you see is not related to whois.com, it shows you have not enabled cURL module for your PHP. Try enabling the PHP cURL module first.
Follow this thread if you are not sure how to enable PHP cURL module: How to enable cURL in PHP / XAMPP
Shirish