BeautifulSoup Add new tag inside a child DIV of a parent DIV
<p>I am a complete beginner with BeautifulSoup and I am now trying to insert a new tag into a children div of a parent  div.</p>

<p>Basically I have this HTML snippet:</p>

<pre><code> &lt;div class=page-content&gt;
  &lt;div class="content-block"&gt;
   //Insert here!
  &lt;/div&gt;
 &lt;/div&gt;
</code></pre>

<p>Here is my current code:</p>

<pre><code>    soup = BeautifulSoup(open("index.html"), "lxml")

    div_page_content = soup.find("div", { "class" : "page-content" })
    content_block = div_page_content.findChildren()

    button_active = soup.new_tag('a')
    button_active.attrs['class'] = 'button active'
    button_active.append('This is a new button!')

    content_block.append(button_active)
    print content_block
</code></pre>

<p>I can fetch the page-content and his children content-block DIV, but the append function doesn't do anything, this is the output that I get:</p>

<pre><code> [&lt;div class="content-block"&gt;\n&lt;/div&gt;, &lt;a class="button active"&gt;This is a new button!&lt;/a&gt;]
</code></pre>

<p>Found the issue, I have to use findNext instead of findChildren. now the append is working fine.</p>

python html parsing beautifulsoup