Extract all tables and h4 from html
Question: I have a html file from which I want to extract all tables and h4 elements.
That is I want to take only tables and h4 from the file and use it somewhere
else. I am using Notepad++ and looking for some pythonscript to do so.

    
    
    <html>
    // header
    <body>
      <div>
      <h4></h4>
      <h4></h4>
      <table>
        // some rows with cells here
        </table>
      // maybe some content here
      <table>
        // a form and other stuff
      </table>
      // probably some more text
     </div>
    </body>
    </html>
    

Thanks


Answer: I suggest using the module
[BeautifulSoup](https://pypi.python.org/pypi/beautifulsoup4).

You could accomplish what you want by doing:

    
    
        from bs4 import BeautifulSoup
    
        code = file("file.html")
        html = code.read()
        soup = BeautifulSoup(html)
        htag = soup.findall('h4')
        tabletag = soup.findall('table')
        for h in htag:
            print h.text
        for table in tabletag:
            print table.text
    

