title: Delete a certain tag with a certain id content from an HTML using python BeautifulSoup
body: <p>I got a suggestion to use BeautifulSoup to delete a tag with a certain id from an HTML. For example, deleting <code>&lt;div id=needDelete&gt;...&lt;/div&gt;</code> Below is my code, but doesn't seem to be working correctly:</p>
  
  <pre><code>import os, re
  from bs4 import BeautifulSoup
  
  cwd = os.getcwd()
  print ('Now you are at this directory: \n' + cwd)
  
  # find files that have an extension with HTML
  Files = os.listdir(cwd)
  print Files
  
  def func(file):
      for file in os.listdir(cwd):
          if file.endswith('.html'):
              print ('HTML files are \n' + file)
              f = open(file, "r+")
              soup = BeautifulSoup(f, 'html.parser')
                  matches  = str(soup.find_all("div", id="jp-post-flair"))
                  #The soup.find_all part should be correct as I tested it to             
                  #print the matches and the result matches the texts I want to delete.
                  f.write(f.read().replace(matches,''))
                  #maybe the above line isn't correct
              f.close()
  func(file)
  </code></pre>
  
  <p>Would you help check which part has the wrong code and maybe how should I approach it?
  Thank you very much!!</p>