title: How do I get all content between two html tags in Python?
body: <p>I try to extract all content (tags and text) from one main tag on html page. For example:</p>
  
  <pre><code>`my_html_page = '''
  &lt;html&gt;
      &lt;body&gt;
         &lt;div class="post_body"&gt;
            &lt;span class="polor"&gt;
               &lt;a class="p-color"&gt;Some text&lt;/a&gt;
               &lt;a class="p-color"&gt;another text&lt;/a&gt;
            &lt;/span&gt;
            &lt;a class="p-color"&gt;hello world&lt;/a&gt;
            &lt;p id="bold"&gt;
                some text inside p
               &lt;ul&gt;
                  &lt;li class="list"&gt;one li&lt;/li&gt;
                  &lt;li&gt;second li&lt;/li&gt;
               &lt;/ul&gt;
           &lt;/p&gt;
           some text 2
           &lt;div&gt;
               text inside div
           &lt;/div&gt;
           some text 3
        &lt;/div&gt;
        &lt;div class="post_body"&gt;
            &lt;a&gt;text inside second main div&lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="post_body"&gt;
            &lt;span&gt;third div&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class="post_body"&gt;
            &lt;p&gt;four div&lt;/p&gt;
        &lt;/div&gt;
        &lt;div class="post"&gt;
            other text
        &lt;/div&gt;
    &lt;/body&gt;
  &lt;html&gt;'''`
  </code></pre>
  
  <p>And I need to get using xpath(<code>"(//div[@class="post_body"])[1]"</code>):</p>
  
  <pre><code>`
         &lt;div class="post_body"&gt;
            &lt;span class="polor"&gt;
               &lt;a class="p-color"&gt;Some text&lt;/a&gt;
               &lt;a class="p-color"&gt;another text&lt;/a&gt;
            &lt;/span&gt;
            &lt;a class="p-color"&gt;hello world&lt;/a&gt;
            &lt;p id="bold"&gt;
                some text inside p
               &lt;ul&gt;
                  &lt;li class="list"&gt;one li&lt;/li&gt;
                  &lt;li&gt;second li&lt;/li&gt;
               &lt;/ul&gt;
           &lt;/p&gt;
           some text 2
           &lt;div&gt;
               text inside div
           &lt;/div&gt;
           some text 3
        &lt;/div&gt;
  `
  </code></pre>
  
  <p>All inside tag <code>&lt;div class="post_body"&gt;</code></p>
  
  <p>I read <a href="https://stackoverflow.com/questions/11122397/how-do-i-get-the-whole-content-between-two-xml-tags-in-python">this topic</a>, but it did not help.</p>
  
  <p>I need to create DOM by beautifulsoup parser in lxml.</p>
  
  <pre><code> import lxml.html.soupparser
   import lxml.html
   text_inside_tag = lxml.html.soupparser.fromstring(my_html_page)
   text = text_inside_tag.xpath('(//div[@class="post_body"])[1]/text()')
  </code></pre>
  
  <p>And i can extract only text inside tag, but I need extract text with tags.</p>
  
  <p>If i tried use this:</p>
  
  <pre><code>for elem in text.xpath("(//div[@class="post_body"])[1]/text()"):
     print lxml.html.tostring(elem, pretty_print=True)
  </code></pre>
  
  <p>I have error: <code>TypeError: Type '_ElementStringResult' cannot be serialized.</code></p>
  
  <p>Help, please.</p>