# -*- coding: cp936 -*-
import urllib2
import imghdr
import os
#connect to a URL
f1 = open("picfiles.txt")
line = f1.readline()
n=1
while line:
n=n+1
line=line.strip('\n')
url= str(line)
url2 = url.replace(" ", "%20") #处理文件包含的空格
imgname=url.rsplit('/', 1)[-1]
if os.path.exists('F:\\xyz\\pic\\{}'.format(imgname)):
print str(n)+' ok\n'
else:
content = urllib2.urlopen(url2).read()
imgtype = imghdr.what('', h=content)
with open('F:\\xyz\\pic\\{}'.format(imgname), 'wb') as f:
f.write(content)
print str(n)+'NO. got Picture name: '+imgname+'\n'
line = f1.readline()
a=raw_input()
f1.close()
python 批量下载图片
最新推荐文章于 2024-04-30 10:57:33 发布