php使用CURL抓取whois记录

发布于 2024-08-20 13:18:09 字数 1090 浏览 5 评论 0原文

示例: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仄言 2024-08-27 13:18:09

Whois.net 检查用户代理。因此,在调用curl_exec之前将这些添加到您的函数中

$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

Whois.net checks user agent. So add these to your function before you call curl_exec

$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
╰◇生如夏花灿烂 2024-08-27 13:18:09

您看到的错误与 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文