download images with google custom search api

前端 未结 2 1911
死守一世寂寞
死守一世寂寞 2020-12-09 07:03

I have used google image api in python to download 20 first image result with the following code:

import os
import sys
import time
from urllib import FancyU         


        
相关标签:
2条回答
  • 2020-12-09 07:47

    You can use this Google APIs Client Library for Python.

    Demo:

    Here is a sample (i change it to):

    from apiclient.discovery import build
    
    service = build("customsearch", "v1",
                   developerKey="** your developer key **")
    
    res = service.cse().list(
        q='butterfly',
        cx=' ** your cx **',
        searchType='image',
        num=3,
        imgType='clipart',
        fileType='png',
        safe= 'off'
    ).execute()
    
    if not 'items' in res:
        print 'No result !!\nres is: {}'.format(res)
    else:
        for item in res['items']:
            print('{}:\n\t{}'.format(item['title'], item['link']))
    

    Output:

    Clipart - Butterfly:
            http://openclipart.org/image/800px/svg_to_png/3965/jonata_Butterfly.png
    Animal, Butterfly, Insect, Nature - Free image - 158831:
            http://pixabay.com/static/uploads/photo/2013/07/13/11/51/animal-158831_640.png
    Clipart - Monarch Butterfly:
            http://openclipart.org/image/800px/svg_to_png/110023/Monarch_Butterfly_by_Merlin2525.png
    

    Yes, there is a limitation for Free edition and you can monitor it from Google developer console:

    here

    Note:

    Go to your Custom Search Engine, then select your custom search engine, then in Basics tab, set Image search option to ON, and for Sites to search section, select Search the entire web but emphasize included site option.

    Links:

    • https://google-api-client-libraries.appspot.com/documentation/customsearch/v1/python/latest/customsearch_v1.cse.html
    • https://developers.google.com/custom-search/json-api/v1/reference/cse/list
    • https://www.google.com/cse/all
    • https://developers.google.com/api-client-library/python/apis/customsearch/v1
    • https://console.developers.google.com/project
    • https://developers.google.com/api-client-library/python/start/get_started
    • https://developers.google.com/api-client-library/python/guide/aaa_apikeys
    0 讨论(0)
  • 2020-12-09 07:47

    I have search api for downloading images to create data set of images may be you should have a look at these !

    1. https://rapidapi.com/contextualwebsearch/api/web-search?endpoint=5b864ca4e4b085e3f407ecca

    2. https://github.com/hardikvasa/webb/blob/master/docs/Documentation.md

    From documentation i like the 2nd one to perfect !

    0 讨论(0)
提交回复
热议问题