Downloading images with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hans Olav Hygen

    #1

    Downloading images with python

    On 23. of October last year a the follwing was posted to this group:
    htmlSource=urll ib.urlopen("htt p://www.godandscien ce.org/images/nebula.jpg")
    # Read from the object, storing the page's contents in 's'.
    s = htmlSource.read ()
    htmlSource.clos e()
    myfile = open("myfile.jp g", "w")
    myfile.write(s)
    myfile.close
    There were two advices (use urllib2 and "wb"). I tried to build this
    script on this basis:

    import win32api
    import win32com
    import urllib2
    gif&p=TAMA&fy=1 900&ty=2005&m=2 1&r_type=TR&r_n o=1")
    htmlSource=urll ib2.urlopen("ht tp://www.godandscien ce.org/images/nebula..jpg")
    # Read from the object, storing the page's contents in 's'.
    s = htmlSource.read ()
    htmlSource.clos e()
    myfile = open("P:\Jobb\P rosjekt\Maaneds oversikt\myfile .jpg", "wb")
    myfile.write(s)
    myfile.close


    But the images get cropped at the bottom. Any suggestions on how to get
    the whole image, and not only 80 - 90% (I run python 2.4 with PythonWin on
    a Windows XP)

    --
    Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
  • Fredrik Lundh

    #2
    Re: Downloading images with python

    Hans Olav Hygen wrote:
    myfile = open("P:\Jobb\P rosjekt\Maaneds oversikt\myfile .jpg", "wb")
    myfile.write(s)
    myfile.close
    make that "myfile.close() "
    But the images get cropped at the bottom.
    files are closed when the program exits (unless it does so in an uncontrolled way),
    so I assume you were trying to access the file while your script was still running.

    </F>



    Comment

    Working...