getting a URL
johnvert at my-deja.com
johnvert at my-deja.com
Fri Jun 9 21:02:56 EDT 2000
In article <8hop1b$c1b$1 at nnrp1.deja.com>,
johnvert at my-deja.com wrote:
> Hello,
>
> As an exercise I'm trying to write a simple cgi script that will get
the
> source code of an html file and echo it to the screen. Here's what I
> have:
>
> import cgi, urllib
>
> (snip)
>
> url = urllib.urlopen("http://www.server.org/foo.html")
> print "<pre>"
> print cgi.escape(url.read()),
> print "</pre>"
>
> But nothing is printed. The problematic line seems to be:
>
> url = urllib.urlopen("http://www.server.org/foo.html")
>
> But the URL I gave it in the actual program is correct. I tried a
few.
> If I run this on the shell (it's meant to be a cgi) it raises IOError
> sayin 'network unreachable'. What could be wrong? Also, why does
> execution stop at:
>
> print "<pre>"
>
> Why isn't the rest (print "</pre>" among others) printed?
>
> Thanks,
> -- John
I changed the code a little bit and ran it on the shell:
print "Content-type: text/html"
print
#form = cgi.FieldStorage()
#if form.has_key("text1"):
# if form["text1"].value != "":
# print cgi.escape(form["text1"].value)
url = urllib.urlopen("http://www.tuxedo.org/~esr/sitemap.html")
print "<pre>"
# print cgi.escape(url.read()),
print "</pre>"
And I get:
$ ./test.py
Content-type: text/html
<pre>
</pre>
Thanks,
-- John
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list