我有html结构
#quick-links
我想要得到的输出如下
<body>
<div class="nc">
<a href=""> Main Heading</a>
</div>
<div class="props">
<div class="nc"> Sub Heading</div>
<div>
<span>properties details1 </span>
</div>
</div>
<div class="nc">
<a href=""> Main Heading 2</a>
</div>
<div class="prop">
<div class="nc"> Sub Heading2</div>
<div>
<span>properties details2 </span>
</div>
</div>
<div class="prop">
<div class="nc"> Sub Heading3</div>
<div>
<span>properties details3 </span>
</div>
</div>
当我尝试使用Main Heading1
Sub Heading1
properties details 1
Main Heading2
Sub Heading2
Properties details2
Sub Heading3
Properties details 3
查找class=nc
时,它返回所有带有find('div[class=nc]')
的元素,我只希望具有主标题的父元素。然后class=nc
通过属性访问,因此我可以按适当的顺序将它们放在数组中。