Google 自定义搜索 API - 反向图片搜索

Google Custom Search API - Reverse image search

我有一组图像,但我缺少相关信息。我希望能够进行 Google 反向图像搜索以查找名称、关键字、相似图像的链接等。我知道抓取搜索结果页面违反了服务条款,并已获得建议使用自定义搜索 API 是正确的方法,但我无法在详细说明反向图像搜索的文档中找到任何内容。如果 API 可以做到这一点,有人能给我指出正确的方向吗?或者验证它实际上是否受支持?

非常感谢!

至于当前 API 我没有发现任何关于反向图像搜索功能的提及。除了基于字符串的查询之外什么都没有。您可以在详细 API 参考资料中查找自己的自定义搜索。

https://developers.google.com/custom-search/docs/xml_results

https://developers.google.com/custom-search/json-api/v1/reference/cse/list

所以 Google-custom-search 不提供该功能。

查看提供的其他 API 后,其中 none 也提供此功能。尝试在此处查看 Google 支持的所有不同类型的 API:

https://developers.google.com/apis-explorer/#p/

因此得出结论,API 形式 Google 没有反向图像搜索。 (这可能会改变,我不能说什么,看看上面提供的链接)

一些供应商提供付费 API。

TinEye API https://services.tineye.com/TinEyeAPI

Incandescent API http://incandescent.xyz/pricing/

否则你必须请求 Google 原谅你对你的宠物项目的小 TOS 违反 :)

第三方解决方案SerpApi,支持抓取Google反向图片。这是付费 API 免费试用。

让我们以丹尼·德维托的这张图片为例:https://i.imgur.com/HBrB8p0.png

示例 python 代码(也可在其他库中使用):

from serpapi import GoogleSearch

params = {
  "engine": "google_reverse_image",
  "google_domain": "google.com",
  "image_url": "https://i.imgur.com/HBrB8p0.png",
  "api_key": "secret_api_key"
}

search = GoogleSearch(params)
results = search.get_dict()

示例 JSON 响应:

...
"image_results": [
  {
    "position": 1,
    "title": "Danny DeVito - Wikipedia",
    "link": "https://en.wikipedia.org/wiki/Danny_DeVito",
    "displayed_link": "https://en.wikipedia.org › wiki › Danny_DeVito",
    "snippet": "Daniel Michael DeVito Jr. (born November 17, 1944) is an American actor, comedian, director, producer, and screenwriter. He gained prominence for his ...",
    "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:EVb7AC9xwHYJ:https://en.wikipedia.org/wiki/Danny_DeVito+&cd=1&hl=en&ct=clnk&gl=us",
    "related_pages_link": "https://www.google.com/search?q=related:https://en.wikipedia.org/wiki/Danny_DeVito&sa=X&ved=2ahUKEwi7uom3wJ_xAhWxHDQIHct6DmQQHzAAegQIBhAQ"
  },
  {
    "position": 2,
    "title": "Danny DeVito - IMDb",
    "link": "https://www.imdb.com/name/nm0000362/",
    "displayed_link": "https://www.imdb.com › name",
    "snippet": "Danny DeVito, Actor: Matilda. Danny DeVito has amassed a formidable and versatile body of work as an actor, producer and director that spans the stage, ...",
    "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:c6r3v14HA7cJ:https://www.imdb.com/name/nm0000362/+&cd=2&hl=en&ct=clnk&gl=us"
  },
  {
    "position": 3,
    "title": "Danny DeVito - Simple English Wikipedia, the free encyclopedia",
    "link": "https://simple.wikipedia.org/wiki/Danny_DeVito",
    "displayed_link": "https://simple.wikipedia.org › wiki › Danny_DeVito",
    "thumbnail": "https://serpapi.com/searches/60cbb000ce87f8cca8f63685/images/9db7034fa3524b93ce0598116fd3b874800a67b8b9434cd54a009f2be5fd0809.jpeg",
    "thumbnail_destination_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Danny_DeVito_by_Gage_Skidmore.jpg/1200px-Danny_DeVito_by_Gage_Skidmore.jpg",
    "image_resolution": "1200 × 1427",
    "snippet": "Daniel Michael \" · Danny\" · DeVito, Jr. (born November 17, 1944) is an American actor, director, producer and screenwriter. He has starred in and directed a number ...",
    "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:2DR2mxjaZbsJ:https://simple.wikipedia.org/wiki/Danny_DeVito+&cd=32&hl=en&ct=clnk&gl=us",
    "related_pages_link": "https://www.google.com/search?q=related:https://simple.wikipedia.org/wiki/Danny_DeVito&sa=X&ved=2ahUKEwi7uom3wJ_xAhWxHDQIHct6DmQQHzAfegQIFhAQ"
  },
  ...
]

查看 documentation 了解更多详情。

免责声明:我在 SerpApi 工作。