doutongfu9484 2016-08-22 22:55
浏览 49
已采纳

为SimpleHTMLDom自动查找ID

I am trying to build a really minimalistic API for Zoover (The holiday review website) and I want to load in the testimonials but they create a different id for each testimonial. Does someone know how I can get the id of the li

This is the code I have already, this just echo's the first testimonial because they all have a different id:

<?php
include_once('libs/simple_html_dom.php');

$html = file_get_html("http://www.zoover.nl/indonesie/lombok/senggigi/campi-sorga/villa/?s=P2xuZz1MYW5ndWFnZV9BTEwmcGFydHlDb21wRmx0SWQ9JnRzdF9wZ3NpemU9MTAmc29ydD1jb250cmlidXRpb24tZGF0ZQ==&page=0");

foreach($html->find('#testimonial13247814 > article > header > h3') as $element)
    echo $element . "<br>";
?>

Hope someone knows how I can fix this.

  • 写回答

1条回答 默认 最新

  • dongzichan2886 2016-08-22 23:08
    关注

    Obviously, don't point to the ID, use the parent <ul> then get its <li> children instead:

    $elements = $html->find('ul.zvr-contributions-list > li > article > header > h3');
    if(!empty($elements)) {
        foreach($elements as $element) {
            echo $element;
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下