【问题标题】:PHP Simple HTML DOM Parser with several identical attributes具有多个相同属性的 PHP 简单 HTML DOM 解析器
【发布时间】:2021-03-08 18:19:53
【问题描述】:

我有这段 HTML 代码:

                <div class='ipsDataItem_main'>
                    <h4 class='ipsDataItem_title ipsContained_container'>
                                <span>
                                    <a href='https://www.' title='Aller au premier message non lu' data-ipsTooltip>
                                        <span class='ipsItemStatus'><i class="fa fa-circle"></i></span>
                                    </a>
                                </span>
                        <span class='ipsType_break ipsContained'>
                            <a href='https://www../topic/81272-une-a' class='' title='Une affaire de '  data-ipsHover data-ipsHover-target='https://www/?preview=1' data-ipsHover-timeout='1.5'>
                                <span>
                                    Une affa.    
                                </span>
                            </a>
                        </span>
                    </h4>
                    <div class='ipsDataItem_meta ipsType_reset ipsType_light ipsType_blendLinks'>
                        <span>
                            Par 
<a href='https://www../profile/5825-crobler/' data-ipsHover data-ipsHover-target='https://www../profile/5825-cr' title="Aller sur le profil " class="ipsType_break"><span style='color:#0099cc'>Crobler</span></a>,
                        </span><time datetime='2021-03-05T1:5:09Z' title='05/01/2021 20:59 ' data-short='2 j'>Vendredi à 20:59</time>
                        dans <a href="https://www../?fo">WEB-DL 2160</a>
                            &nbsp;&nbsp;
        <ul class='ipsTags ipsTags_inline ipsList_inline '>
<li >
    <a href="https://www../tags/une_ails/" class='ipsTag' title="" rel="tag"><span></span></a>
    
</li>
    </ul>   
                    </div>
                </div>

我想提取时间标签“05/01/2021 20:59”的标题。我尝试了以下代码:

foreach($html->find('div[class=ipsDataItem_main] a') as $f) {
     
   echo $f->title;
   
}

我有所有标题,但没有我想要的。请问我该怎么做? 我怎么能只选择我想要的“标题”?例如“ipsType_break ipsContained”类中的标题?

提前谢谢你。

【问题讨论】:

  • $html-&gt;find('.ipsDataItem_meta time') 是否提供正确的项目?

标签: php parsing simple-html-dom


【解决方案1】:
foreach($html->find('.ipsContained a') as $element) {
       echo $element->title ; 
}

【讨论】:

    【解决方案2】:

    这只是找到正确路径以找到您所追求的数据的一个案例......

    $html->find('.ipsDataItem_meta time')
    

    【讨论】:

      猜你喜欢
      • 2018-06-30
      • 2012-06-22
      • 2012-01-17
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 2016-07-30
      • 1970-01-01
      相关资源
      最近更新 更多