[Tutor] (no subject)

Daniel Yoo dyoo@hkn.eecs.berkeley.edu
Wed, 11 Apr 2001 03:34:21 -0700 (PDT)


On Wed, 11 Apr 2001, wong chow cheok wrote:

> hai this is chow cheok again. got another problem here.
> this is what i have so far
> 
> f=open('you','w')
> html=urllib.urlopen("http://www.guardian.co.uk/Distribution/Artifact_Trail_Block/0,5184,179821-0-,00.html").read()
> f.write(html)
> 
> but when i read it i don't get the file from the website. all i get is 
> rubbish. why is that. even when i try to write a line ex:"i am a boy'

What kind of contents are you getting?  When I visit that link with my
Netscape browser, it spits out the "Sorry, the page you requested is not
available at this moment."  Could you check the URL again?


Also, it's usually helpful to show us what a small portion of the file
looks like: although it might not be understandable, it might contain
clues about why it's not doing the right thing.


> i get rubbish too. the only thing i can write to the file is '12345abcd' and 
> other strings similar to it. how do i write the information i got from the 
> website into the file. it can print out fine when i type
> print html.

Your program looks ok; I'm guessing either the web site is down, or the
url needs to be corrected.


By the way, try the following program, and see if it works ok for you:

###
f = open('evens.txt', 'w')
f.write("This is a file that contains even numbers.\n\n")
for i in range(20, 2):
    f.write(i)
    f.write(' ')
f.close()
###

It does enough file writing to help you see if file output is working
well.