html:
<h2>...</h2>
<p>...</p>
<p>...</p>
<p>...</p>
<h2>...</h2>
<p>...</p>
<p>...</p>
<p>...</p>
<p>...</p>
Expected result:
<p>...</p>
<p>...</p>
<p>...</p>
I mean, getting all content between h2 elements
Every element has a nextSibling method, so you can just get the first h2 element, then loop through the next siblings until you hit the second element.
Pseudo Code (assuming firstElem is the h2 element):
p_tags = []
next = firstElem.nextSilbing
while next.name != "h2":
p_tags.append(next)
next = next.nextSibling
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With