from BeautifulSoup import BeautifulSoup
import re
soup = BeautifulSoup('<html><p>foo</p></html>')
r = soup.findAll('p', text=re.compile('foo'))
print(r[0].parent)
Using BeautifulSoup's findAll to search html element's innerText to get same result as searching attributes?