dongshi1880 2017-09-21 02:23
浏览 143
已采纳

HTML dom解析器获取内部h5数据

<div class="username-info-area">
                <img src="https://image5.sahibinden.com/users/47/06/46/p200_profile_14470646_8126809.png" class="user-profile-photo" height="50" width="50" alt="">
                <h5>familya yapı Gayrimenkul Gyo ltd şti</h5>
                </div>

I want to get h5 data. I can access div.username-info-area.

$items = $new_data->find('div.username-info-area', 0)->outertext; 
        echo $items . '<br>';
  • 写回答

1条回答 默认 最新

  • dongzaotiao2863 2017-09-21 02:29
    关注

    Run an if clause inside of your foreach loop, check this example out for instance:

    The script below will make sure that if there's an h5 value it will print $div and its outertext.

    <?php
    foreach ($new_data->find('div[class=username-info-area]') as $div)
    {
        if($div->find('h5') !== '')
        {
            print_r($div->outertext);
        }
    }
    ?>
    

    Or you can run another foreach loop inside of the next foreach loop, for example.

        <?php
    foreach ($new_data->find('div[class=username-info-area]') as $div)
    {
        foreach($div->find('h5') as $h5)
        {
            print_r($h5->outertext);
        }
    }
    ?>
    

    I hope this help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办