title: Insert html string into BeautifulSoup object
body: <p>I am trying to insert an html string into a BeautifulSoup object. If I insert it directly, bs4 sanitizes the html. If take the html string and create a soup from it, and insert that I have problems with using the <code>find</code> function. <a href="https://stackoverflow.com/questions/15455148/find-after-replacewith-doesnt-work-using-beautifulsoup">This post thread</a> on SO suggests that inserting BeautifulSoup objects can cause problems. I am using the solution from that post and recreating the soup each time I do an insert. </p>
  
  <p>But surely there's a better way to insert an html string into a soup.</p>
  
  <p><strong>EDIT: I'll add some code as an example of what the problem is</strong></p>
  
  <pre><code>from bs4 import BeautifulSoup
  
  mainSoup = BeautifulSoup("""
  &lt;html&gt;
      &lt;div class='first'&gt;&lt;/div&gt;
      &lt;div class='second'&gt;&lt;/div&gt;
  &lt;/html&gt;
  """)
  
  extraSoup = BeautifulSoup('&lt;span class="first-content"&gt;&lt;/span&gt;')
  
  tag = mainSoup.find(class_='first')
  tag.insert(1, extraSoup)
  
  print mainSoup.find(class_='second')
  # prints None
  </code></pre>