1
我想用文本内容搜索特定标签。例如:按标签内容使用BeautifulSoup搜索
<a href="http://goinghere.com">Lets go somewhere</a>
我想通过搜索文本'Lets go somewhere'找到上述内容。 我目前正在使用re。可以在BeautifulSoup中完成,还是在这种情况下使用re更好?
我想用文本内容搜索特定标签。例如:按标签内容使用BeautifulSoup搜索
<a href="http://goinghere.com">Lets go somewhere</a>
我想通过搜索文本'Lets go somewhere'找到上述内容。 我目前正在使用re。可以在BeautifulSoup中完成,还是在这种情况下使用re更好?
s = BeautifulSoup(...)
s.find(text='Lets go somewhere')
你也可以使用正则表达式。
Using BeautifulSoup to find a HTML tag that contains certain text
编辑:当你使用它的命令行上find方法打印字符串,这实际上是它返回的对象只是一种表象;你可以访问它的父属性来访问它的BeautifulSoup标签对象。
感谢您的帮助。 – 3eee3