BeautifulSoup: parse only part of the page
===

I want to parse a part of html page, say

    my_string = """
    <div class="comment">
        <p>Some text. Some text. Some text. Some text. Some text. Some text.
           <a href="#">Link1</a>
        </p>
        <img src="image.png" />
    </div>
    """

I pass this string to BeautifulSoup:

    soup = BeautifulSoup(my_string)
    # add rel="nofollow" to <a> tags
    # return comment to the template

But during parsing BeautifulSoup adds `<html>`,`<head>` and `<body>` tags (if using lxml or html5lib parsers), and I don't need those in my code. The only way I've found up to now to avoid this is to use `html.parser`.

I wonder if there is a way to get rid of redundant tags using lxml - the quickest parser.


