[Tutor] Accessing the Web using Python
Henry Steigerwaldt
hsteiger@comcast.net
Tue Feb 11 20:58:19 2003
To All:
I am trying to understand why the process of accessing
a Web site sometimes fails. I am attempting to get data from
the following Web site:
http://isl715.nws.noaa.gov/tdl/forecast/fwc.txt
If you go there you will notice that this site contains a VERY
LONG list of data. The code I am using in a small program
I am working on is this:
______________________________________________
import urllib
fwcURL = "http://isl715.nws.noaa.gov/tdl/forecast/fwc.txt"
try:
print "Going to Web for data"
fwcall = urllib.urlopen(fwcURL).read()
print "Successful"
print "Will now print all of the data to screen"
print "fwcall = ", fwcall
except:
print "Could not obtain data from Web"
______________________________________________
Using this code the previous day, I had absolutely no problem
getting the data. However yesterday using the same code,
most of the time this site could not be accessed at all.
When I could not get anything back from this site using the
above code, I tried going to the site using Microsoft Internet
Explorer (I am using a windows PC). And I immediately got
access to the site.
I also noticed that a few times I would be able to access the
site (i.e. the "Successful" would print to the screen), but
each time absolutely NOTHING would be stored in the
"fwcall" variable, unlike successful times when all the text
information WAS stored in the variable.
Does anyone know what the heck is going on here? Is there
a way to have more positive results obtaining data from the
Web using some other Python coding, or is it sometimes just
hit and miss?
I just tried this same code tonight and once again it works
great! I am really puzzled by all this. When one writes a
program to access the Web, as long as the site accessed is
not "down," one should anticipate always being able to get
the data.
Is there a better and hence much more successful way to
do what I want? Please also send any response to my
email.
Thanks much!
Henry Steigerwaldt
Hermitage, TN
Email: hsteiger@comcast.net