I need to add the count statement to give urllib access the tuple of
urls. urllib needs to be given a different value each time in order to
check all the urls. This is the only way I could get the value (web) in
urllib to change each time. I tried indenting the count statement and
it runs without error but still only makes one pass.&nbsp; <br>
<br>
Thanks<br clear="all"><br>
Message: 1<br>
Date: Sun, 20 Nov 2005 22:26:10 -0500<br>
From: Kent Johnson &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:kent37@tds.net">kent37@tds.net</a>&gt;<br>
Subject: Re: [Tutor] Website monitoring program.<br>
Cc: <a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:tutor@python.org">tutor@python.org</a><br>
Message-ID: &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:43813E52.5010708@tds.net">43813E52.5010708@tds.net</a>&gt;<br>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed<br>
<br>
Adisegna wrote:<br>
&gt; How do I get the counting loop to come back around? It makes one pass<br>
&gt; fine. How do I get it to come back up and go through again?<br>
<br>
You
have to indent the statement 'count += 1' so it is part of the loop.
But you misunderstand the for loop - the count variable is not needed
at all. Your variable 'i' will receive each element of urls, one each
time through the loop. For a simpler example,<br>
<br>
&nbsp;&gt;&gt;&gt; u = ['a', 'b', 'c']<br>
&nbsp;&gt;&gt;&gt; for letter in u:<br>
&nbsp;... &nbsp; print letter<br>
&nbsp;...<br>
a<br>
b<br>
c<br>
<br>
So instead of<br>
count = 0<br>
for i in urls:<br>
 &nbsp; &nbsp;web = urls[count]<br>
<br>
you can write simply<br>
for web in urls:<br>
<br>
See the Python tutorial for more examples of for loops:<br>
<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://docs.python.org/tut/node6.html#SECTION006200000000000000000" target="_blank">http://docs.python.org/tut/node6.html#SECTION006200000000000000000</a><br>

<br>
Kent<br>
<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt; ------------------------------
<div id="mb_0">-------------------------<br>&gt; import urllib, smtplib<br>&gt;<br>&gt; urls = (&quot;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website0.net/imalive.asp" target="_blank">http://website0.net/imalive.asp
</a>&quot;,<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website1.net/imalive.asp" target="_blank">http://website1.net/imalive.asp</a>&quot;,<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website2.net/imalive.asp" target="_blank">
http://website2.net/imalive.asp</a>&quot;,<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website3.net/imalive.asp" target="_blank">http://website3.net/imalive.asp</a>&quot;,
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website4.net/imalive.asp" target="_blank">http://website4.net/imalive.asp</a>&quot;<br>&gt; &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://website4.net/imalive.asp%22" target="_blank">
http://website4.net/imalive.asp%22</a>&gt;,)<br>&gt;<br>&gt; count = 0<br>&gt; for i in urls:<br>&gt; &nbsp; &nbsp; web = urls[count]<br>&gt;<br>&gt; &nbsp; &nbsp; for site in urllib.urlopen(web):<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; good = &quot;400 Bad Request&quot;
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; bad = &quot;Invalid Hostname&quot;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; smtpserver = '<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.authentium.com/" target="_blank">mail.authentium.com</a> &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://mail.authentium.com/" target="_blank">
http://mail.authentium.com</a>&gt;'<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; RECIPIENTS = ['<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:my@address.com">my@address.com</a> &lt;mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:my@address.com">
my@address.com</a>&gt;']<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; SENDER = '<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:website-Verification@address.com">website-Verification@address.com</a><br>&gt; &lt;mailto:<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:website-Verification@address.com">
website-Verification@address.com</a>&gt;'<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; mssg = site<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if good in site:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print &quot;OK&quot;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file = open(&quot;test.log&quot;, &quot;a&quot;)
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines('sometext : ')<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(site)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(&quot;\n&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.close()<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; elif bad in site:
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print &quot;NOT OK&quot;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file = open(&quot;test.log&quot;, &quot;a&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines('metro-ams : ')<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(site)
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(&quot;\n&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.close()<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; session = smtplib.SMTP(smtpserver)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; smtpresult = session.sendmail(SENDER, RECIPIENTS, mssg)
<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if smtpresult:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; errstr = &quot;&quot;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for recip in smtpresult.keys():<br>&gt;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; errstr = &quot;&quot;&quot;Could not delivery mail to: %s<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Server said: %s<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %s<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %s&quot;&quot;&quot; % (recip, smtpresult[recip][0],
<br>&gt; smtpresult[recip][1], errstr)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; raise smtplib.SMTPException, errstr<br>&gt;<br>&gt;<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; else:<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file = open(&quot;test.log&quot;, &quot;a&quot;)<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines('Another type of error occurred : ')<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(site)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.writelines(&quot;\n&quot;)<br>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; text_file.close()
<br>&gt; print web<br>&gt; count +=1<br>&gt; print count</div>
<br>-- <br>Arthur DiSegna<br>Network Operations Center<br>Authentium, Inc.