I want to extract all HTML between specific HTML tags.
<html>
<div class="class1">Included Text</div>
[...]
<h1><b>text</b></h1><span>[..]</span><div>[...]</div>
[...]
<span class="class2">
[...]</span>
so want to grep all HTML (tags & values) between the class1 div and the class2 span.
Included Text
<h1><b>text</b></h1><span>[..]</span><div>[...]</div>
Also there are multiple occurrences within the HTML file so I want to match them all. Here is what I mean:
<html>
(first occurrence)
<div class="class1">Included Text</div>
[...]
<h1><b>text</b></h1><span>[..]</span><div>[...]</div>
[...]
<span class="class2">
[...]</span>
(2nd occurrence)
<div class="class1">Included Text</div>
[...]
<h1><b>text</b></h1><span>[..]</span><div>[...]</div>
[...]
<span class="class2">
[...]</span>
(third occurrence)
<div class="class1">Included Text</div>
[...]
<h1><b>text</b></h1><span>[..]</span><div>[...]</div>
[...]
<span class="class2">
[...]</span>
</html>
I've been searching for answers using Beautifulsoup 4. However, all questions/answers are related to extracting values between text, but that is not want I want. I was also wondering if this is even possible with Beautifulsoup or whether I must use regex instead.