我正在尝试使用简单的语法来查找标签内文本的多个可能选项。
假设我有以下代码:
multi= soup.find("h3", text="Experience").replace_with(code)
我想查找 text = "Experience"
或 "Summary"
。
我尝试过:
multi= soup.find("h3", {text:["Experience",'Summary']}).replace_with(code)
但没有成功。
最佳答案
您可以使用正则表达式
import re
soup.find(text=re.compile('Experience|Summary')).replace_with(code)
关于python - 在 HTML 中同时查找多个 "Text"选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31205637/