downloading web images

Discussion in 'Python' started by Joe, Oct 23, 2005.

  1. Joe

    Joe Guest

    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
     
    Joe, Oct 23, 2005
    #1
    1. Advertising

  2. Hi !

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

    Have a good day.

    MCI
     
    Do Re Mi chel La Si Do, Oct 23, 2005
    #2
    1. Advertising

  3. 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.
     
    Steven D'Aprano, Oct 23, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe
    Replies:
    0
    Views:
    425
  2. Joe
    Replies:
    4
    Views:
    4,006
  3. Stephen Kellett

    Downloading images from the web - how

    Stephen Kellett, Jul 9, 2004, in forum: Java
    Replies:
    2
    Views:
    323
    Stephen Kellett
    Jul 9, 2004
  4. renil
    Replies:
    2
    Views:
    357
    renil
    Jul 4, 2006
  5. Hans Olav Hygen

    Downloading images with python

    Hans Olav Hygen, Oct 20, 2006, in forum: Python
    Replies:
    1
    Views:
    257
    Fredrik Lundh
    Oct 20, 2006
Loading...

Share This Page