Coding/Python 삽질기2005. 5. 5. 10:42
[CODE]# -*- coding: cp949 -*- import urllib import re import string print "="*50 print "Images In Web Pages Download Script!" print "="*50 num_start = 0 num_end = 3000 num_current = 0 WORK_DIR = "d:delete" def saveJPG(num, imageName): print imageName filename = "d:delete\%d.jpg" %num print filename source = urllib.urlopen(imageName) try: file = open(filename, "wb") file.write(source.read()) file.close except: print "Error on open %s" % filename page = "http://www.yahoo.co.kr" a = urllib.urlopen(page) data = a.readlines() p = re.compile('.*img src=.*') for line_one in data: m = p.match(line_one) if m: tmp = string.find(line_one, 'img src=') tmp_line = line_one[tmp+9:] tmp2 = string.find(tmp_line, 'jpg'); tmp_line = tmp_line[:tmp2+3] saveJPG(num_current, tmp_line) num_current += 1 print "Good Day!" [/CODE]

'Coding > Python 삽질기' 카테고리의 다른 글

helloworld.cgi  (0) 2006.10.15
이미지 파일을 읽어오는 소스  (0) 2005.05.05
Python 관련 사이트 모음  (0) 2005.03.27
Posted by chobocho