By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,941 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,941 IT Pros & Developers. It's quick & easy.

downloading web images

P: n/a
Joe
I'm just wandering if I'm doing this correct way I'm trying to download an
image and store it into a file this does the job, but created file does not
apear to be an image, it works fine and I can open image, I'm just
wandering if there is a better way of doing this.

htmlSource=urllib.urlopen("http://www.godandscience.org/images/nebula.jpg")
# Read from the object, storing the page's contents in 's'.
s = htmlSource.read()
htmlSource.close()
myfile = open("myfile.jpg", "w")
myfile.write(s)
myfile.close

Thanks
Oct 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi !

Note :
urllib2.urlopen is more fast and more "modern"
open("myfile.jpg", "wb") if better for binary

Have a good day.

MCI


Oct 23 '05 #2

P: n/a
On Sun, 23 Oct 2005 06:52:26 +0000, Joe wrote:
I'm just wandering if I'm doing this correct way I'm trying to download an
image and store it into a file this does the job, but created file does not
apear to be an image, it works fine and I can open image, I'm just
wandering if there is a better way of doing this.


What do you mean that the file does not appear to be an image? If it works
fine and you can open the image, then what is the problem?
--
Steven.

Oct 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.