如何用BeautifulSoup找到含有文字内容的标签?

如何用BeautifulSoup找到含有文字内容的标签?

print soup.find(‘h2’)
#>>

this is cool #12345678901

print soup.find(‘h2’, text=pattern)
#>> this is cool #12345678901
print soup.find(‘h2’, text=pattern).parent
#>>

this is cool #12345678901

print soup.find(‘h2’, text=pattern) == soup.find(‘h2’)
#>> False
print soup.find(‘h2’, text=pattern) == soup.find(‘h2’).text
#>> True
print soup.find(‘h2’, text=pattern).parent == soup.find(‘h2’)
#>> True

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注