urllib2 - Downloading a picture via urllib and python -


So I'm trying to create a Python script that downloads webcmix and puts them in the folder on my desktop . I have seen some such programs here that do something similar, but I do not like anything. The way I got the most, it's fine () I tried to use this code:

  & gt; & Gt; & Gt; Import urllib & gt; & Gt; & Gt; Image = urllib.URLopener () & gt; & Gt; & Gt; Image.retrieve ("http://www.gunnerkrigg.com//comics/00000001.jpg", "00000001.jpg") ('00000001.jpg', & lt; httplib.HTTPMessage Example 0x1457a80 & gt;)  

Then I searched for my computer for "00000001.jpg", but the cached image of what I got was the picture. I do not even believe this file was saved on my computer. Once I understand how to download files, I think how to handle the rest. I essentially only use one loop and split the string on '00000000' 'jpg' and '00000000' To the largest number, which I have to define in some way. The best way to do this, or how to download the file properly?

Thank you!

Edit 6/15/10

The script is completed here, it saves the files in any of the directories you have selected. For some strange reasons, the files are not downloaded. And they did just now. Any suggestion about how to clean it will be highly appreciated. I am currently working on how many comics exist on the site, so I can get the latest one instead of leaving the program after raising few exceptions.

urlib import os comicCounter = len (os.listdir ('/ file')) + 1 # reads the number of files in the folder to download on the next comic error = 0 DR def_download_comic (Url, comicName): "" "URL = http://www.example.com comicName = '00000000.jpg'" "" image = urllib.URLPener () Download a comic in the form of image. Download URL (URL, ComicName) # Download ComicName Comic Controller & Lt; = 1000: # Not the most elegant solution os.chdir ('/ file') # Set where to download the files: If the comic quarters & lt; 10: # is required to break into 10 ^ n sections because comic names are a set of zero, followed by a number comic number = str ('0000000' + str (comiccontron)) # string in which there is an eight-digit comic number ComicName = str (comicNumber + .jpg ") # string containing the filename url = str (" http://www.gunnerkrigg.com//comics/ "+ comicname) #makes the comic comicCounter + = 1 # URL for To go to the comic counter, before the next comic download, an exception download_comic (ur L, ComicName) # raises, if the comic uses the above function to download the print URL, 10 and lt; = comicCounter <100: comicnumber = str ('000000' + str (comic quant) ) comicname = Str (comicnumber ".jpg") url =str ("http:>

:

  import urllib urllib.urlretrieve ("http: // wwwun Nerkrigg.com//comics/00000001.jpg", "00000001.jpg" )  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -