Find stacked div class with Simple HTML DOM Parser

為{幸葍}努か 提交于 2019-12-24 02:16:43

问题


I am using PHP Simple HTML DOM Parser and there is a section in the html page with the following source:

<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>

How can I now get the list of links with using the stacked class identifier?

Here's what I've currently tried:

  • List item $html->find('.box-content padding-top-1 padding-bottom-1 font-size-3'));
    • returns empty
  • List item $html->find('.box-content'));
    • returns other page elements in a box
  • List item $html->find('.box-content+padding-top-1+padding-bottom-1+font-size-3'));
    • never mind :(

回答1:


Or you can try this:

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



回答2:


For targeting an element with multiple classes, use dot (.) as the separator between classes. Spaces indicate a parent -> child relationship.

So, in your example, you would need:

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


来源:https://stackoverflow.com/questions/7387958/find-stacked-div-class-with-simple-html-dom-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!