Remove lines getting empty after BeautifulSoup decompose
问题 I am trying to strip certain HTML tags and their content from a file with BeautifulSoup . How can I remove lines that get empty after applying decompose() ? In this example, I want the line between a and 3 to be gone, as this is where the <span>...</span> block was, but not the line in the end. from bs4 import BeautifulSoup Rmd_data = 'a\n<span class="answer">\n2\n</span>\n3\n' print(Rmd_data) #OUTPUT # a # <span class="answer"> # 2 # </span> # 3 # # END OUTPUT soup = BeautifulSoup(Rmd_data,