python - 精确文本匹配 if 语句 python beautifulsoup
问题描述
我正在尝试使用以下代码查找“精确文本匹配”。该网站是:https ://www.girafferestaurant.co.nz/menu 。当我打印 (soup.find_all(text=True)) 时,我可以取回文本并进行搜索,但我只想匹配或不匹配,具体取决于单词/短语(在本例中为“在 Giraffe 提供”)是否在陈述。
以下是我尝试过的。
text = soup.find_all(text=True)
if 'offering at Giraffe' in text:
print ("Match")
else:
print ("No Match")
另外,我使用了 text = soup.find_all('p') 但文本并不总是在 p 标签中,因为它跨越不同的站点。
解决方案
推荐阅读
- javascript - ReactJS/Javascript/Graphql/React-apollo:无法读取未定义的属性“加载”
- jquery - Jquery分离/附加分离的一部分
- sql - 将数据从 Excel 导入 SQL
- c++ - 网络流量捕获的内部结构
- angular - 单击复选框以选择行将隐藏该行的内容
- python-3.x - 我在 django 2.0 Reverse 中遇到错误,因为找不到参数 '('',)' 的 'delete'。尝试了 1 种模式:['delete\\/(?P
[^/]+)\\/$'] - c# - 通过数据网格中的其他两列获取列值
- git - 更新了 .gitignore 文件,但状态仍然报告未暂存的文件
- php - 混合身份验证 Facebook 登录引发异常
- c# - Unity 如何让 GameObject 实例在被引用时被销毁?