使用新的自定义搜索API在Google图片上搜索图片? [英] Search image on Google images with the new Custom Search API?

查看:107
本文介绍了使用新的自定义搜索API在Google图片上搜索图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在测试这段代码:

So, I am testing this piece of code :

import requests
import json


searchTerm = 'parrot'
startIndex = '0'
searchUrl = "http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" + \
    searchTerm + "&start=" + startIndex
r = requests.get(searchUrl)
response = r.content.decode('utf-8')
result = json.loads(response)
print(r)
print(result)

响应为:

<Response [200]>
{'responseData': None, 'responseStatus': 403, 'responseDetails': 'This API is no longer available.'}

似乎我正在尝试使用旧的API,并且现在已不推荐使用.当我查看 Google自定义搜索API 时,看不到任何直接搜索的方法google图片,使用新的API甚至可以做到吗?

Seems that I am trying to use the old API and it is deprecated now. When I check on the Google Custom Search API I don't see any way to search straight on google images, is this even possible with the new API ?

推荐答案

可能的是,这里有新的API参考:
https://developers.google.com/custom-search /json-api/v1/reference/cse/list

It is possible, here is new API reference:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list

import requests
import json

searchTerm = 'parrot'
startIndex = '1'
key = ' Your API key here. '
cx = ' Your CSE ID:USER here. '
searchUrl = "https://www.googleapis.com/customsearch/v1?q=" + \
    searchTerm + "&start=" + startIndex + "&key=" + key + "&cx=" + cx + \
    "&searchType=image"
r = requests.get(searchUrl)
response = r.content.decode('utf-8')
result = json.loads(response)
print(searchUrl)
print(r)
print(result)

那很好,我刚刚尝试过.

That works fine, I just tried.

这篇关于使用新的自定义搜索API在Google图片上搜索图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆