目前有一批图片地址,有些已经被删掉了,以下用python查找出还存在的图片资源
import urllib2
from urllib2 import URLError
f=open("images.txt","r")
img_exist=open("exist.txt","w+")
img_not_exist=open("notexist.txt","w+")
for line in f:
try:
response=urllib2.urlopen(line)
except URLError, e:
img_not_exist.write(line)
else:
img_exist.write(line)
response.close()
finally:
pass
f.close()
img_exist.close()
img_not_exist.close()