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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效