开发者

Find stacked div class with Simple HTML DOM Parser

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


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'));


Or you can try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜