Quote
URL of image folder:
http://www.gamersglo....uk/screenshot/
Image prefix:
world-of-warcraft-pc-0
First image number:
1
Last image number:
15
Leading 0 (this is for images 1-9 if for example image 1 is seen as 01) (y/n):
y
Extension:
jpg
http://www.gamersglo....uk/screenshot/
Image prefix:
world-of-warcraft-pc-0
First image number:
1
Last image number:
15
Leading 0 (this is for images 1-9 if for example image 1 is seen as 01) (y/n):
y
Extension:
jpg
The default download folder is C:\Images
if the folder doesn't already exist, the program creates it.
There is an error right now, where if there is a leading 0, it will download 10.jpg and 010.jpg
Also, the program will only work for less than 100 images if there is a leading 0.
Anyways, here's the code:
Code:
import urllib;
import os;
import random;
os.chdir('c:\\');
if os.path.exists('C:\\Images'):
os.chdir('C:\\Images');
else:
os.system('mkdir Images');
os.chdir('C:\\Images');
print('Enter URL of image folder: ');
picture_page = raw_input();
print('Enter image prefix: ');
img_prefix = raw_input();
print('Enter starting image number: ');
img_fnum = raw_input();
print('Enter last image number: ');
img_lnum = raw_input();
print('Leading 0 (y/n): ');
lead0 = raw_input();
print('Enter file extension: ');
ext = raw_input();
a = range(int(img_lnum));
for x in a:
if lead0 == 'y':
if x < 10:
a[int(x)] = '0' + str(x+1);
else:
a[int(x)] = str(x+1);
rfolder = random.random();
rfolder = rfolder * 7397;
rfolder = str(int(rfolder));
os.system('mkdir ' + rfolder);
for x in a:
print('Source: ' + picture_page + img_prefix + str(a[int(x)-1]) + '.' + ext);
print('Destination: ' + os.getcwd() + '\\' + rfolder + '\\' + img_prefix + str(a[int(x)-1]) + '.' + ext);
urllib.urlretrieve(picture_page + img_prefix + str(a[int(x)-1]) + '.' + ext, os.getcwd() + '\\' + rfolder + '\\' + img_prefix + str(a[int(x)-1]) + '.' + ext);
If you have some ideas as to how to better automate the process, or maybe how to check whether the image actually exists on the server before the program tries to download it, or any other suggestions or tips for me please let me know!
Thanks!

New Topic/Question
Reply



MultiQuote



|