python爬取图片

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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爬取图片的主要内容,如果未能解决你的问题,请参考以下文章