One thing I did for a Sigil plugin (written in Python), that would delete empty spans, was to cycle through storing all the tags and text, giving each a number, and a pir number (initialised at 0), then run through and when it came to an end span, work backward to find the previous unpaired span, then continuing on through to end of file.
Then remove all the empty spans and their end tags, then rewrite the file back in order.
You could do something similar to remove *your* desired spans.
the plugin was in the post
here if you want to see what I did. [And see better than how it's worded here

]