from BeautifulSoup import BeautifulSoup
import re
html_text = """
<h2>this is cool 
<h2>this is nothing</h2>
<h1>foo 
<h2>this is interesting 
<h2>this is blah 
"""
soup = BeautifulSoup(html_text)
for elem in soup(text=re.compile(' #\\S{11}')):
    pass
Использование BeautifulSoup для поиска тега HTML, содержащего определенный текст