title: Remove only specific table tags from HTML files using BeautifulSoup
body: <p>I am working on parsing hundreds of HTML documents using BeautifulSoup package. My code is able to parse entire documents very well.</p>
  
  <p>I want to remove the content of all table tags depending upon on a condition. Since few tables (as per HTML tags) might not actually be tables, rather text presented inside a table. If the content of a table has more than 75% of characters as numbers, I would like to treat it as actual table and remove it, otherwise I would like to keep it.</p>
  
  <p>I am new to Python and not sure how can I remove entire content of only specific  tables.</p>
  
  <p>Suppose my HTML document is:</p>
  
  <pre><code>&lt;document&gt;
  &lt;table&gt;
  100
  &lt;/table&gt;
  &lt;text&gt;
  Hello Word
  &lt;/text&gt;
  &lt;table&gt;
  Test
  &lt;/table&gt;
  &lt;/document&gt;
  </code></pre>
  
  <p>Following code will generate content of entire HTML document i.e. </p>
  
  <pre><code>100
  Hello Word 
  Test 
  </code></pre>
  
  <p>What I want is:</p>
  
  <pre><code>Hello Word 
  Test 
  </code></pre>
  
  <p>Please note that code also contains one function that is useful to check if text is useful or not. I am counting both alphabetical as well as numerical characters separately because there could be a lot of white spaces and other garbage characters.</p>
  
  <p>Please help me in removing tables which are not useful i.e which contain more than 75% numerical characters. Please also note that table need not to be direct child of document.</p>
  
  <pre><code>from bs4 import BeautifulSoup
  import html5lib
  def isTableUseful(text): #Returns True if table is to be included
      try:
          countAlpha = 0
          countNumeric = 0
          for char in text:
              if char.isalpha():
                  countAlpha += 1
              if char.isnumeric():
                  countNumeric += 1
          FracNumeric = countNumeric/(countNumeric+countAlpha)
          return FracNumeric &lt; 0.75
      except:
          return False
  soup = BeautifulSoup("&lt;document&gt;&lt;table&gt;100&lt;/table&gt;&lt;text&gt;Hello Word&lt;/text&gt;&lt;table&gt;Test&lt;/table&gt;&lt;/document&gt;", "html5lib")
  print ('\n'.join([e.encode("utf-8") for e in soup.recursiveChildGenerator() if isinstance(e,unicode) and e.strip()!=""]))
  </code></pre>