June 2000
Intermediate to advanced
556 pages
8h 45m
English
On machines with Internet or intranet connections, it is useful to be able to point the xmln and xmlv utilities at arbitrary URLs. Python has excellent support for Internet protocols. The following simple program retrieves the contents of an arbitrary URL and outputs its contents on standard output.
CD-ROM reference=4035.txt
C>type geturl.py
"""
Simple utility to retrieve a URL and print
its contents to standard output.
"""
import sys
import os
from urllib import urlretrieve, urlcleanup
def geturl(url):
try:
filename,headers = urlretrieve(url)
print open(filename,"r").read()
finally:
urlcleanup()
if __name__ == "__main__":
geturl(sys.argv[1])
Here is an example of the geturl utility ...
Read now
Unlock full access