首页 > 代码库 > python爬取图片

python爬取图片

#coding=utf-8  
  
import urllib2  
import os  
import re 
count=0#计数君
for line in open("./imagenet1.synset.geturls"):
    imagename=str(count+1)
    print(imagename)
    try:
        url=urllib2.urlopen(line)
        data=url.read()  
        with open("/opt/fish/"+imagename+".jpg", "wb") as code: 
            count+=1 
            code.write(data)  
            code.close()
    except Exception as e:
        print(e)
        continue
        raise e
    else:
        pass
    

 

python爬取图片