【问题标题】:How get block with data from remote html? [duplicate]如何从远程 html 获取数据块? [复制]
【发布时间】:2013-09-08 15:46:32
【问题描述】:

美好的一天。

为了获取远程 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) 更新日期

有人知道如何制作吗?

【问题讨论】:

    标签: php dom file-get-contents


    【解决方案1】:

    以下代码块运行后,$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 日" }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-29
      • 2015-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-19
      • 1970-01-01
      相关资源
      最近更新 更多