Php Xpath - 从代码源获取标题

时间:2014-09-29 16:15:38

标签: php xpath

您好我想从一个网页源获取所有标题。所以我尝试使用php xpath并编写:

$dom = new DOMDocument();
@$dom->loadHTMLFile('http://some-site.com/egypt/book-shops');
$xpath = new DOMXPath($dom);
$entries = $xpath->query("//td[@class='icon']/i/@title");
foreach($entries as $e) {
  echo 'Title is : ' . $e->textContent . '<br />';
}

网络源代码是:

<td class="icons">
            <i title="info@some-site.de" data-shopnameid="Good Life" class="icon email-small message-shop" id="message-shop-8"></i>
                                                                                                            ... ... ...

我错了,错误是什么。我只是白屏。

1 个答案:

答案 0 :(得分:1)

class不是icon,而是icons

$entries = $xpath->query("//td[@class='icons']/i/@title");