title: How can I categorize text according to html tags from extracted text from website source code
body: <p>Is there a way to categorize the text extracted from a HTML source code and place each word under the HTML tags that are categorized</p>
  <p>Eg - H1 - My First Heading
  The element defines a large heading</p>
  <pre><code> p  - My first paragraph. 
  </code></pre>
  <p>Like wise categorizing all text according to the HTML tags and meta tags.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from bs4 import BeautifulSoup
  from bs4.element import Comment
  import urllib.request
  
  
  def tag_visible(element):
      if element.parent.name in ['style', 'script', 'head', 'title', 'meta', '[document]']:
          return False
      if isinstance(element, Comment):
          return False
      return True
  
  
  def text_from_html(body):
      soup = BeautifulSoup(body, 'html.parser')
      texts = soup.findAll(text=True)
      visible_texts = filter(tag_visible, texts)  
      return u" ".join(t.strip() for t in visible_texts)
  
  html = urllib.request.urlopen('https://www.w3schools.com/html/html_intro.asp').read()
  print(text_from_html(html))</code></pre>
  </div>
  </div>
  </p>