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 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图