【问题标题】:php using CURL to grab whois recordphp 使用 CURL 获取 whois 记录
【发布时间】:2011-01-14 15:49:15
【问题描述】:

示例: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;
 } 

【问题讨论】:

  • 本题的正则表达式有什么关系?
  • 删除了正则表达式引用。他们可能想在从 CURL 获得结果后使用正则表达式,这可以通过我的上一条评论来避免。
  • 确保您阅读 - whois.net/terms-and-conditions,特别是这一部分:您无权通过使用大量自动化的电子流程访问或查询 WHOIS.NET 系统,除非是合理的注册域名或修改现有注册所必需的。

标签: php curl screen-scraping call whois


【解决方案1】:

Whois.net 检查user agent。所以在调用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);

【讨论】:

    【解决方案2】:

    您看到的错误与 whois.com 无关,它表明您没有为 PHP 启用 cURL 模块。尝试先启用 PHP cURL 模块。

    如果您不确定如何启用 PHP cURL 模块,请关注此主题:How to enable cURL in PHP / XAMPP

    希尔什

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-09
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多