简体   繁体   English

Google图片搜寻(Python)

[英]Google Search by Image in Python

Is there a way to use the Google search by Image feature in Python? 有没有办法在Python中使用Google按图片搜索功能? I was considering taking an image file from a specified location and using that file to get relevant search results. 我当时正在考虑从指定位置获取图像文件,并使用该文件来获取相关的搜索结果。 I have looked through the Google Custom Search API and cannot seem to find anything on this topic. 我已经浏览了Google自定义搜索API,但似乎找不到与此主题相关的任何内容。 Any help would be appreciated. 任何帮助,将不胜感激。

The following code snippet shows how to make a request to the Google Image Search API using Python. 以下代码段显示了如何使用Python向Google Image Search API发出请求。 This sample assumes Python 2.4 or higher. 本示例假定使用Python 2.4或更高版本。 You may need to download and install simplejson. 您可能需要下载并安装simplejson。

import urllib2
import simplejson

url = ('https://ajax.googleapis.com/ajax/services/search/images?' +
       'v=1.0&q=barack%20obama&userip=INSERT-USER-IP')

request = urllib2.Request(url, None, {'Referer': /* Enter the URL of your site here */})
response = urllib2.urlopen(request)

# Process the JSON string.
results = simplejson.load(response)
# now have some fun with the results...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM