0

再会。

对于获取远程 html,我使用代码:

$file = file_get_contents('http://who.is/whois/abate.com');
libxml_use_internal_errors(true); //Prevents Warnings, remove if desired
$dom = new DOMDocument();
$dom->loadHTML($file);

我得到了html:

<table>
    <tbody>
        <tr>
    <th>Expires On</th>
    <td><span data-bind-domain="expiration_date" style="visibility: visible;">November 28, 2015</span></td>
    </tr>
            <tr>
    <th>Registered On</th>
    <td><span data-bind-domain="expiration_date" style="visibility: visible;">June 03, 1995</span></td>
    </tr>
            <tr>
    <th>Updated On</th>
    <td><span data-bind-domain="expiration_date" style="visibility: visible;">June 01, 2013</span></td>
    </tr>
        </tbody></table>

我想得到:

1) 日期到期

2) 注册日期

3) 更新日期

有人知道如何制作吗?

4

1 回答 1

2

以下代码块运行后,$values应包含域名的到期、注册和更新日期:

$xpath = new DOMXPath($dom);
$result = $xpath->evaluate('//table/tbody/tr[th="Expires On" or th="Registered On" or th="Updated On"]/td/span');

$values = array();
foreach($result as $node) {
    $values[] = $node->textContent;
}
数组(3){
  [0]=>
  string(17) "2015 年 11 月 28 日"
  [1]=>
  string(13) "1995 年 6 月 3 日"
  [2]=>
  string(13) "2013 年 6 月 1 日"
}
于 2013-09-05T00:03:23.490 回答