Script to check a page
<p>I have a script that alerts me by mail when a phrase changes on a web page.  I tried many things, but I can't fix the <strong>isAvailable()</strong> function: the script says "not available" every time, whether or not I give it an available server.  Have you any clues?</p>

<pre><code># CONFIG
TARGET_KIMSUFI_ID = "160sk1" # something like 160sk1
TARGET_DESCR      = ""
EMAIL_FROM_ADDRS  = ""
EMAIL_TO_ADRS     = ""
EMAIL_SMTP_LOGIN  = EMAIL_FROM_ADDRS
EMAIL_SMTP_PASSWD = ""
EMAIL_SMTP_SERVER = ""

# CODE
import urllib.request
import smtplib
import time

def isAvailable():
    rawPageContent = urllib.request.urlopen("https://www.kimsufi.com/en/servers.xml").read()
    rawPageContent = str(rawPageContent)
    poz = rawPageContent.find(TARGET_KIMSUFI_ID)
    row = rawPageContent[poz:]
    poz = row.find("&lt;/tr&gt;")
    row = row[:poz]
    searchText = "Currently being replenished"
    poz = row.find(searchText)
    return poz != -1

def sendEmailWithMessageAvailable():
    msg = "From: KIMSUFI HUNTER &lt;"+EMAIL_FROM_ADDRS+"&gt;\r\n"+\
        "To: "+EMAIL_TO_ADRS+"\r\n"+\
        "Subject: [KIMSUFI] "+TARGET_DESCR+" is now AVAILABLE!\r\n"+\
        "\r\n"+\
        "kimsufi-hunter.py has detected that "+TARGET_DESCR+" is now ["+time.ctime()+"] available!\r\n"+\
        "https://www.kimsufi.com/en/\r\n"
    server = smtplib.SMTP(EMAIL_SMTP_SERVER)
    server.starttls()
    server.login(EMAIL_SMTP_LOGIN,EMAIL_SMTP_PASSWD)
    server.sendmail(EMAIL_FROM_ADDRS, EMAIL_TO_ADRS, msg)
    server.quit()

while True:
    if isAvailable():
        print(time.ctime() + " -- KIMSUFI "+TARGET_DESCR+" not available")
        nextSleep = 5 #5secs
    else:
        print(time.ctime() + " -- KIMSUFI "+TARGET_DESCR+" AVAILABLE!!! -- sleeping for 5 minutes")
        sendEmailWithMessageAvailable()
        nextSleep = 5*60 #5mins
    time.sleep(nextSleep)
</code></pre>

<p>Your <code>isAvailable()</code> function returns <code>True</code> if the website is available, <code>False</code> otherwise. You should change the <code>if</code> statement to:</p>

<pre><code>if not isAvailable():
    ...
</code></pre>

python