【发布时间】: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