假设我有以下标记:
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Books, Literature and Languages
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>Hello</p>
</div>
</div>
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Business and Consumer Information
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>World</p>
</div>
</div>
<p>Some text in between</p>
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Fine Arts and Music
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>Hello</p>
</div>
</div>
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Genealogy
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>World</p>
</div>
</div>
我想包装每组.handorgel__*元素,以便它们包含在一个容器中<div class="handorgel">。
<div class="handorgel">
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Books, Literature and Languages
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>Hello</p>
</div>
</div>
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Business and Consumer Information
</button>
</h3>
<div class="handorgel__content">
<div class="handorgel__content__inner">
<p>World</p>
</div>
</div>
</div>
<p>Some text in between</p>
<div class="handorgel">
<h3 class="handorgel__header">
<button class="handorgel__header__button">
Fine Arts and Music
</button>
</h3>
每个组中可以有任意数量的元素,以及页面的任意数量的组。我怎样才能检测到这些组并适当地包装它们?我目前DOMDocument在这个项目中使用了很多东西,所以如果可能的话,我也想将它用于这个目的,除非有明显更好的方法。
素胚勾勒不出你