How do I replace the contents of a HTML document with random text using BeautifulSoup?
<p>Here is code that I've written.</p>

<pre><code>    from bs4 import BeautifulSoup
import urllib
import string, random

def readHtml():
    sock = urllib.urlopen('1041956_Page1.htm')
    soup = BeautifulSoup(sock,'html.parser')
    paraTags = soup.find_all('p')
    for para in paraTags:
        if(para.get_text() is not None):
            para.replace_with(randomizeText(para.get_text())


def randomizeText(text):
    length = len(text)
    newWord = ''.join(random.choice(string.lowercase) for x in range(length-1))
    return newWord

if __name__ == "__main__":
    readHtml()
</code></pre>

<p>This gives me an error that says </p>

<blockquote>
  <p>ValueError: Cannot insert None into a tag.</p>
</blockquote>

<p>I want the  BeautifulSoup object to be replaced with random text would like to rebuild the html from it. Any help would be appreciated. Thanks!</p>

<p>I am not sure but have you considered the case in which</p>

<pre><code>&lt;p&gt;&lt;/p&gt;
</code></pre>

<p>is empty.</p>

<p>So,</p>

<pre><code>para.get_text() 
</code></pre>

<p>will return None.</p>

python html python-2.7 beautifulsoup