【问题标题】:Find stacked div class with Simple HTML DOM Parser使用 Simple HTML DOM Parser 查找堆叠的 div 类
【发布时间】:2011-09-12 12:35:51
【问题描述】:

我正在使用PHP Simple HTML DOM Parser,html 页面中有一个部分,其来源如下:

<div class="box-content padding-top-1 padding-bottom-1 font-size-3">
    <ul>
        <li>
            <a href="link1">linkdescription 1</a>
        </li>
        <li>
            <a href="link2">linkdescription 2</a>
        </li>
    </ul>
</div>

我现在如何使用堆叠类标识符获取链接列表?

这是我目前尝试过的:

  • List item $html-&gt;find('.box-content padding-top-1 padding-bottom-1 font-size-3'));
    • 返回空
  • List item $html-&gt;find('.box-content'));
    • 在一个框中返回其他页面元素
  • List item $html-&gt;find('.box-content+padding-top-1+padding-bottom-1+font-size-3'));
    • 没关系:(

【问题讨论】:

    标签: parsing class html domparser


    【解决方案1】:

    要定位具有多个类的元素,请使用点 (.) 作为类之间的分隔符。空格表示父->子关系。

    因此,在您的示例中,您需要:

    List item $html->find('.box-content.padding-top-1.padding-bottom-1.font-size-3'));
    

    【讨论】:

      【解决方案2】:

      或者你可以试试这个:

      List item $html->find('div[class=box-content padding-top-1 padding-bottom-1 font-size-3]');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-05
        • 2013-03-28
        • 1970-01-01
        • 2018-05-11
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多