title: Rename HTMLs based on DIV
body: <p>Although I studied the earlier questions (<a href="https://stackoverflow.com/questions/2491222/how-to-rename-a-file-using-python">How to rename a file using Python</a>), It's for me still not clear to rename all my HTML in folder x, based on the H1 of the div in my HTML file. </p>
  
  <pre><code>&lt;div id="page_header" class="page_header_email_alerts"&gt;
      &lt;h1&gt;
          &lt;span itemprop="headline"&gt;Redhill Biopharma's (RDHL) CEO Dror Ben Asher on Q4 2014 Results - Earnings Call Transcript&lt;/span&gt;
      &lt;/h1&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Does someone have a suggestion?
  I have made with bs4 a solution, but it does not loop through all my htmls:</p>
  
  <pre><code>import os
  from bs4 import BeautifulSoup
  import textwrap
  
  directory ='C:/Research syntheses - Meta analysis/SeekingAlpha/test/'
  for filename in os.listdir(directory):
      if filename.endswith('.html'):
          fname = os.path.join(directory,filename)
          with open(fname, 'r') as f:
              soup = BeautifulSoup(f.read(),'html.parser')
              headline = soup.find(itemprop='headline').text
  os.rename(filename, headline+'.html')
  </code></pre>