from BeautifulSoup import BeautifulSoup, Comment
soup = BeautifulSoup(
    """<html>
<body>
<p>paragraph 1</p>
<p>paragraph 2</p>
<!--some comment text-->
<p>paragraph 3</p>
</body>
</html>"""
    )

def right_comment(e):
    return isinstance(e, Comment) and e == 'some comment text'
Beautiful Soup - identify tag based on position next to comment