I’ve got a document like this:
<p class="top">I don't want this</p>
<p>I want this</p>
<table>
<!-- ... -->
</table>
<img ... />
<p> and all that stuff too</p>
<p class="end>But not this and nothing after it</p>
I want to extract everything between the p[class=top] and p[class=end] paragraphs.
Is there a nice way I can do this with BeautifulSoup?
node.nextSiblingattribute is your solution:This complicated condition is to be sure that you’re accessing attributes of HTML tag and not string nodes.