title: How To Test For Type of Beautiful Soup Object?
body: <p>This may be a very basic Python question, although I am running across it in Beautiful Soup.</p>
  
  <p>The basic thing I want to do is to extract only the output text from an HTML file.</p>
  
  <p>For example in the HTML file included below I would like to extract only 0123, abc, def and ghi but not the tags and attributes.</p>
  
  <p>As best I understand BS I should be able to recurse through the descendants of the HTML tag and include only things that are NavigableStrings.</p>
  
  <p>The problem is I don't know how to write the if statement to test for the type. See the comment in the python code below.</p>
  
  <p>Any solutions?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;0123&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div&gt;
          &lt;p&gt;abc&lt;/p&gt;def
          &lt;a href="wxy.z"&gt;ghi&lt;/a&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  # -*- coding: UTF-8 -*-
  from bs4 import BeautifulSoup
  
  with open('simple.html', 'r') as inf:
      soup = BeautifulSoup(inf.read(), 'lxml')
      for e in soup('html'):
          for d in e.descendants:
              print d     # HERE I WANT TO SKIP EXCEPT FOR NAVIGABLE STRINGS
  </code></pre>