使用简单 HTML DOM 解析器查找堆叠的 div 类
我正在使用 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->find('.box-content padding-top-1 padding-bottom-1 font-size-3'));
- 返回空
列表项 $html->find('.box-content'));
- 返回框中的其他页面元素
List item $html->find('.box-content+padding-top-1+padding-bottom-1+font-size-3'));
- 没关系:(
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: