title: beautiful soup extract tags delete text
body: <p>I'm trying to use Beautifuloup to extract html tags and delete the text. For example take this html:</p>
  
  <pre><code>html_page = """
  &lt;html&gt;
  &lt;body&gt;
  &lt;table&gt;
  &lt;tr class=tb1&gt;&lt;td&gt;Lorem Ipsum dolor Sit amet&lt;/td&gt;&lt;/tr&gt;
  &lt;tr class=tb1&gt;&lt;td&gt;Consectetuer adipiscing elit&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Aliquam Tincidunt mauris eu Risus&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;Vestibulum Auctor Dapibus neque&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  """
  </code></pre>
  
  <p>The desired result is:</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;table&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here's what I've got so far:</p>
  
  <pre><code>def get_tags(soup):
      copy_soup = soup
      for tag in copy_soup.findAll(True):
          tag.attrs = {} # removes attributes of a tag
          tag.string = ''
  
      return copy_soup
  
  print get_tags(soup)
  </code></pre>
  
  <p>Using tag.attrs = {} works for removing all tag attributes. But when I try using tag.string or tag.clear() I'm just left with <code>&lt;html&gt;&lt;/html&gt;</code>. I understand that what is probably happening is on the first iteration using <code>tag.string</code> or <code>tag.clear()</code> is removing all contents within the html tags.</p>
  
  <p>I'm unsure how to remedy this. Perhaps recursively delete text from children first? Or is there a simpler approach I'm missing?</p>