title: BeautifulSoup get all tags of strings
body: <p>I am a BeautifulSoup newbie and I want to know if there is any way to get the tags by string. Example:</p>
  
  <pre><code>from bs4 import BeautifulSoup
  s = s = "&lt;blockquote&gt;&lt;i&gt;&lt;b&gt;Quote&lt;/b&gt;&lt;/i&gt;&lt;/blockquote&gt;&lt;br /&gt;SOME DESIRED TEXT &lt;h3&gt;&lt;i&gt;This is a title&lt;/i&gt;&lt;/h3&gt;"
  soup = BeautifulSoup(s, "html.parser")
  soup_all =  soup.findAll()
  for s in soup.strings:
      print get_tags_by_string(s)
  </code></pre>
  
  <p>And get the output of <code>get_tags_by_string</code>:</p>
  
  <pre><code>Quote -&gt; blockquote
  Quote -&gt; i
  Quote -&gt; b
  SOME DESIRED TEXT  -&gt; Plain
  This is a title -&gt; h3
  This is a title -&gt; i
  </code></pre>
  
  <p>I am looking the official doc but it seems there is no fucntionality for this.</p>
  
  <p>Thank you in advance!!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I've explored this workaround but inner tags are not detected...</p>
  
  <pre><code>import bs4
  s = "&lt;blockquote&gt;&lt;i&gt;Quote&lt;/i&gt;&lt;/blockquote&gt;&lt;br /&gt;text &lt;h3&gt;This is a title&lt;/h3&gt;"
  soup = bs4.BeautifulSoup(s, "html.parser")
  soup_all = soup.find_all()
  for asds in soup.contents:
      if isinstance(asds, bs4.element.Tag) and asds.text != "":
          print "%s -&gt; %s" % (asds.text, asds.name)
      elif isinstance(asds, bs4.element.NavigableString):
          print "%s -&gt; None" % asds
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Quote -&gt; blockquote
  text  -&gt; None
  This is a title -&gt; h3
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>This solution works for me:</p>
  
  <pre><code>for content in soup.contents:
      if isinstance(content, bs4.element.Tag) and content.text != "":
          print "%s -&gt; %s" % (content.text, content.name)
          # Nested tags
          nested_tags = content.find_all()
          for nested_tag in nested_tags:
              print "%s -&gt; %s" % (nested_tag.text, nested_tag.name)
      elif isinstance(content, bs4.element.NavigableString):
          print "%s -&gt; None" % content
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Quote -&gt; blockquote
  Quote -&gt; i
  Quote -&gt; b
  SOME DESIRED TEXT  -&gt; Plain
  This is a title -&gt; h3
  This is a title -&gt; i
  </code></pre>
  
  <p>What do you think about this workaround? Could be valid? </p>
  
  <p>Thank you in advance!</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>This workaround is not valid for inner nested tags....</p>