duangutian1426 2014-09-29 16:15
浏览 45
已采纳

Php Xpath - 从代码源获取标题[重复]

This question already has an answer here:

Hi I want to get all titles from one web page source. So I try to use php xpath and I write:

$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 />';
}

the web source code is:

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

Where I wrong, what is error. I just get white screen.

</div>
  • 写回答

1条回答 默认 最新

  • duanguanya3052 2014-09-29 16:21
    关注

    The class isn't icon, it's icons:

    $entries = $xpath->query("//td[@class='icons']/i/@title");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?