首页 > 解决方案 > 在 if 语句中查找多个单词或字符串

问题描述

我正在使用 Python 和 Beautiful Soup 4 从网站获取一些文本。我正在使用for 循环说:“仅当返回的文本不包含单词lorem时才打印文本”

我的问题是,除了多个单词,我怎么能做同样的事情?例如loremipsumdolor

这是我尝试过的,我不确定如何继续:

for title in soup.select('.panel-heading h3 a'):
    if 'lorem' not in title.text:
        print(title.text, '-->', title.get('href'))

标签: python-3.xbeautifulsoup

解决方案


推荐阅读