The URL I have provided has "Wine" 1 time on the website, but it is performing the "Else" function by printing the message.
# Import requests (to download the page)
import requests
# Import BeautifulSoup (to parse what we download)
from bs4 import BeautifulSoup
# Import Time (to add a delay between the times the scape runs)
import time
# Import smtplib (to allow us to email)
import smtplib
# Import URLOPEN
from urllib.request import urlopen
# while this is true (it is true by default),
while True:
# set the url,
# set the headers like we are a browser,
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
# download the URL
response = requests.get(url, headers=headers)
# parse the downloaded URL and grab all text
soup = BeautifulSoup(response.text, "lxml")
# if the number of times the defined word occurs on the page is 1,
if str(soup).find('Wine') == 1:
# print "Please wait 15 seconds",
print("Please wait 15 seconds")
# pause 15 seconds,
time.sleep(15)
# continue with the script,
continue
# but if the defined word occurs any other number of times,
else:
print("Word occurs on website more or less than 1 time.")
break