In [4]:
# dog http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n02084071
# cat
import shutil
import requests
import uuid
import os

dog_url="http://www.image-net.org/api/text/imagenet.synset.geturls?wnid=n02084071"
dog_response=requests.get(dog_url, stream=True)
dogs=dog_response.text.split()

for url in dogs[:10]:
    print(url)
    try:
        response = requests.get(url, stream=True)

        file_name= '{}.jpg'.format(uuid.uuid4())
        with open( os.path.join('dog', file_name), 'wb') as out_file:
            shutil.copyfileobj(response.raw, out_file)
    except:
        print('invalid url')


http://farm1.static.flickr.com/164/358144227_01e5544b79.jpg
http://www.pantherkut.com/wp-content/uploads/2007/04/2.jpg
http://farm3.static.flickr.com/2325/1891011832_cb5d5098c2.jpg
http://farm1.static.flickr.com/1/2800688_afe83c164a.jpg
http://farm1.static.flickr.com/46/151838410_88d0d8198b.jpg
http://www.jameswilsonphotography.com/photogallery/photo3146/Dog.jpg
http://farm1.static.flickr.com/147/421773683_7705c66f95.jpg
http://farm1.static.flickr.com/48/146403300_0128782865.jpg
http://static.flickr.com/5/7220886_ece3a7ecea.jpg
http://www.mierdas.es/wp-content/uploads/2006/12/perro-con-dentadura.jpg

In [13]:
rm -rf dog/*.jpg

In [5]:
ls dog


2fa81c13-e1f9-497c-a145-a131ad432f82.jpg
3e58641e-e40e-4baf-98eb-db723b443910.jpg
3efce652-6388-4845-acf4-4f0efc3dbc5e.jpg
573c096c-d71f-4808-bf2b-34502e036bdf.jpg
795c7ebd-c596-4b8d-886a-d5091567b7e6.jpg
7f3b7443-363e-44de-9e85-8b3659132b78.jpg
87813e8f-4dce-4871-a1b9-b998ccfb6de5.jpg
9a9d2742-5566-4714-b08e-b84de8daada6.jpg
b4bf89a4-1a53-4f6e-9a51-b18ff15ef953.jpg
c43610e1-d6b8-4655-b60c-1d8f8fa4fd2f.jpg

In [6]:
response.ok


Out[6]:
True

In [7]:
response


Out[7]:
<Response [200]>

In [ ]: