1

再会。

行 DOM HTML:

<div class="raw_data">

<span data-bind-domain="raw_registrar_lookup">

Domain Name: ABATE.COM
<br>
Registrar URL: http://www.godaddy.com
<br>
Registrant Name: Jim Elgin
<br>
Registrant Organization: ABATE of Ohio, Inc.
<br>
Name Server: NS43.DOMAINCONTROL.COM
<br>
Name Server: NS44.DOMAINCONTROL.COM
<br>

<br>
For complete domain details go to:
<br>
http://who.godaddy.com/whoischeck.aspx?domain=ABATE.COM<br>
    <br>
    Information Updated: Wed, 4 Sep 2013 23:43:18 UTC<br>



</span>

</div>

要获取类名 *raw_data* 的 html div,我使用代码:

$file = file_get_contents('http://who.is/whois/abate.com');
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML($file);
$xpath = new DOMXPath($dom);
$res = $xpath->evaluate('//div[contains(concat(' ',@class,' '),"raw_data")]');

但不工作...

1)请告诉我哪里出错了?

2)我只能在 span 中获取 html<span data-bind-domain="raw_registrar_lookup">吗?

4

1 回答 1

1

获取信息的方法之一<span>..</span>是使用 preg_match。正则表达式解析 HTML 可能很麻烦,但这里有一个您提供的数据的工作示例。

$data = '
<div class="raw_data">

<span data-bind-domain="raw_registrar_lookup">

Domain Name: ABATE.COM
<br>
Registrar URL: http://www.godaddy.com
<br>
Registrant Name: Jim Elgin
<br>
Registrant Organization: ABATE of Ohio, Inc.
<br>
Name Server: NS43.DOMAINCONTROL.COM
<br>
Name Server: NS44.DOMAINCONTROL.COM
<br>

<br>
For complete domain details go to:
<br>
http://who.godaddy.com/whoischeck.aspx?domain=ABATE.COM <br>
    <br>
    Information Updated: Wed, 4 Sep 2013 23:43:18 UTC<br>

</span>

</div>';

preg_match("/<span[^>]*>(.*?)<\/span>/si", $data, $matches);
//           ^         ^       ^    ^
//           <span.....>      </span>
//                                    s = make dot match all characters
//                                    i = case insensitive search

print_r($matches[1]);

这有帮助吗?

另一种方法是使用xml_parse_into_struct.

于 2013-09-05T17:51:45.293 回答