您好我想从一个网页源获取所有标题。所以我尝试使用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>
... ... ...
我错了,错误是什么。我只是白屏。
答案 0 :(得分:1)
class
不是icon
,而是icons
:
$entries = $xpath->query("//td[@class='icons']/i/@title");