How to download a file from an HTTP server given the URL?

J

J. W. McCall

Hopefully a simple question: how do I download a file (jpg image) to my
hard drive from a website assuming I have its (the image's) URL? I
tried urllib.urlretrieve() and it's not working. I'm relatively new to
Python, so I'm probably make a dumb mistake or looking in the wrong place.

Any help would be appreciated.

Thanks,

J. W. McCall
 
J

J. W. McCall

Ok, update: I got it to work downloading to the default temp directory
with default temp names using urllib.urlretrieve(). If I try to specify
the path and filename, if says that the file doesn't exist. I don't see
why it doesn't just create that file.

Thanks,

J. W. McCall
 
P

Peter Hansen

J. W. McCall said:
Ok, update: I got it to work downloading to the default temp directory
with default temp names using urllib.urlretrieve(). If I try to specify
the path and filename, if says that the file doesn't exist. I don't see
why it doesn't just create that file.

Also try to give examples of real code when asking questions like this.
What path and filename, etc? Show snippets that you typed at the
interactive prompt and cut and paste (not retyped!) directly into the
message. Also specify your platform and the version of Python you are
using, and any other critical info you can think of. We're not
mind-readers**.

-Peter

** Well, some people here are, but they've already read your mind and
concluded that you will find the answer on your own, given enough time,
so they aren't wasting their valuable time helping you. Bastards. :)
 
M

Michel Claveau/Hamster

This sample run Ok on my windows :


def recupfileweb(adr, repenregistrement):
data = urllib.urlopen(adr).read()
list = string.split(adr,'/')
nomlocal=list[-1]
f = open(repenregistrement+nomlocal, "wb")
f.write(data)
f.close()
print('Fichier '+repenregistrement+nomlocal+' téléchargé depuis '+adr)


recupfileweb("http://ponx.org/downloads/toto.zip","c:\\rdest\\") #==>
C:\rdest\toto.zip
 
S

Sylvain Hellegouarch

Hi Peter,

You are right. But why being so rude?

Have you never been a newbie somewhere asking dumb question badly?

I don't understand that...

- Sylvain
 
P

Peter Hansen

Sylvain said:
Hi Peter,

You are right. But why being so rude?

"Rude" by what definition? If you mean I was being "uncivil",
I disagree. If you mean my reply was "unpolished" or "coarse"
(maybe "blunt"?), then I can't argue with that. But you
wouldn't have posted if you thought I had merely not taken
the time to prepare a more refined wording for delicate
ears, so you must have meant something like "uncivil".

So I was not being rude. I was being helpful, in a blunt way.
I said nothing offensive, or at least not intentionally.
I asked the OP to give more info, and I added a bit of
coarse humour as well. Perhaps you were looking for offense where
none was intended...
Have you never been a newbie somewhere asking dumb question badly?

No doubt, a long time ago, but it makes no difference to whether
or not I try to help people help themselves. By showing some
newbies how to ask better questions, I not only help them, but I
reduce the burden on those of us who try to provide support in this
forum.
I don't understand that...

Re-read my posting without looking for offense, and maybe you
will. (Note: nothing in _this_ posting was intended to offend
either. Just for reference.)

-Peter
 
J

John J. Lee

Sylvain Hellegouarch said:
Peter Hansen wrote: [...]
Hi Peter,

You are right. But why being so rude?
[...]

Can't see any trace of rudeness in Peter's message.


John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top