(num_elements=1000)
return "<html>" + "\n".join(elements) + "</html>"
Randomly generate an invalid HTML document.
Randomly generate an invalid HTML document.
Randomly generate an invalid HTML document .
def rdoc(num_elements=1000):
    """Randomly generate an invalid HTML document."""
    tag_names = ['p', 'div', 'span', 'i', 'b', 'script', 'table']
    elements = []
    for i in range(num_elements):
        choice = random.randint(0,3)
        if choice == 0:
            # New tag.
            tag_name = random.choice(tag_names)
            elements.append("<%s>" % tag_name)
        elif choice == 1:
            elements.append(rsentence(random.randint(1,4)))
        elif choice == 2:
            # Close a tag.
            tag_name = random.choice(tag_names)
            elements.append("</%s>" % tag_name)
    return "<html>" + "\n".join(elements) + "</html>"
def rdoc ( num_elements = 1000 ) : tag_names = [ 'p' , 'div' , 'span' , 'i' , 'b' , 'script' , 'table' ] elements = [ ] for i in range ( num_elements ) : choice = random . randint ( 0 , 3 ) if choice == 0 : # New tag. tag_name = random . choice ( tag_names ) elements . append ( "<%s>" % tag_name ) elif choice == 1 : elements . append ( rsentence ( random . randint ( 1 , 4 ) ) ) elif choice == 2 : # Close a tag. tag_name = random . choice ( tag_names ) elements . append ( "</%s>" % tag_name ) return "<html>" + "\n" . join ( elements ) + "</html>"