0

I am using Python with Beautiful Soup 4 to fetch some text from a website. I am using a for loop to say: "Print the text only if the returned text does not contain the word lorem"

My question is, how can I do the same but for multiple words? For example for lorem, ipsum and dolor.

This is what I have tried and I am unsure how to proceed:

for title in soup.select('.panel-heading h3 a'):
    if 'lorem' not in title.text:
        print(title.text, '-->', title.get('href'))
Arete
  • 948
  • 3
  • 21
  • 48
  • 2
    Does this answer your question? [Check if multiple strings exist in another string](https://stackoverflow.com/questions/3389574/check-if-multiple-strings-exist-in-another-string) and negate the result if you want negation. This isn't really a beautiful soup problem, from what I can tell, just a string searching issue. – ggorlen Dec 27 '19 at 19:02
  • I know it's not a BS4 problem. That was to show the context of the script. I saw the question you linked to earlier, but since I am new to Python I didn't have the experience to realize that these questions are in fact the same. Thank you for pointing that out. – Arete Dec 27 '19 at 23:15

0 Answers0