Google Lens is a visual search tool that allows users to upload images to find similar or exact matches of items and products. By analyzing the visual content of the uploaded image, Google Lens can identify and compare it with its online image database. This capability is especially valuable for discovering visually similar products, whether clothing, furniture, or artwork.

Scraping Google Lens' (visual and exact matches)

Why scrape Google Lens?

If you need to search for many images, doing so one by one could be time-consuming. Using our Google Lens API, you'll be able to do it programmatically.

Google Lens API - SerpApi
Scrape Google Lens page with SerpApi’s Google Lens API. Knowledge graph, text, visual matches, including title, link, source, and more.

Preparation

You can use a simple GET request or a dedicated SDK based on your programming language, including Python, JavaScript, and more. In this post, we'll use the GET request method in Python.

Preparation for accessing SerpApi API

  • Register at serpapi.com for free to get your SerpApi Api Key.
  • Create a new main.py file
  • Install requests with
pip install requests

Here is what the basic setup looks like

import requests
SERPAPI_API_KEY = "YOUR_REAL_SERPAPI_API_KEY"

params = {
    "api_key": SERPAPI_API_KEY, #replace with your real API Key
    # soon
}

search = requests.get("https://serpapi.com/search", params=params)
response = search.json()
print(response)

With these few lines of code, we can access all of the search engines available at SerpApi, including Google Lens. We'll need to adjust the parameters based on our needs.

Scrape Google Lens using Python

The Google Lens API requires a valid image link that is publicly available. We'll use this link to put in the url. For example, I have this image here: https://i.imgur.com/HBrB8p0.png. Here is how to search for this image on Google Lens.

import requests
SERPAPI_API_KEY = "YOUR_REAL_SERPAPI_API_KEY"

params = {
  "api_key": SERPAPI_API_KEY, #replace with your real API Key
  "engine": "google_lens",
  "url": "https://i.imgur.com/HBrB8p0.png",
}

search = requests.get("https://serpapi.com/search", params=params)
response = search.json()
print(response)

You should be able to see the response from our API in the console.

Inspect page
If you want to have a better view of the response, you can grab the search_metadata > id on the response and access this page: https://serpapi.com/searches/{the search ID you got}/inspect

Be sure to replace it with your search ID. Here is what my search looks like:

Google Lens scraping result.

On the left side, you can see the HTML version; you can click on any of the images, and it'll scroll the response to the correct position on the right side. As you can see, we provide the initial search results in this format:

{
"position": -,
"title": "Danny DeVito",
"link": "https://www.imdb.com/media/rm2640023040/nm0000362",
"source": "IMDb",
"source_icon":
"https://serpapi.com/searches/67e7602fdbaf923e5de31778/images/75844c3641e5f327d71f86b6cf522521ed2f4d4f5037c079d22dece044a1b073.png",
"thumbnail":
"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcRTh4Zy6emTiteMDJoE7d29Hq1x_B78Ot_wv3CiUTmdgpm3G6MH",
"thumbnail_width": 266,
"thumbnail_height": 189,
"image": "https://m.media-amazon.com/images/M/MV5BNzc0NjMxMDM5MV5BMl5BanBnXkFtZTcwMTUyNjYwMw@@._V1_.jpg",
"image_width": 400,
"image_height": 285
},

You can do anything you want with the data available.

Scraping different tabs

On Google Lens, you can navigate the menu at the top to see different results depending on which menu item you click.

Google Lens menu

To do this with our API, you need to add a "type" parameter with these options:

all - All (Default)
products - Products
exact_matches - Exact Matches
visual_matches - Visual Matches.

Scrape the exact matches tab from Google Lens

Now, let's adjust the parameter to access the specific tab. This time, we're going for exact matches tab.


params = {
    "api_key": SERPAPI_API_KEY, #replace with your real API Key
    "engine": "google_lens",
    "url": "https://i.imgur.com/HBrB8p0.png",
    "country": "US", # You can adjust to specific country
    "type": "exact_matches"
}
scraping Google Lens - Exact Matches tab section

Scrape the visual matches tab from Google Lens

Similar to the previous method, this time, we should set the type to visual_matches to scrape the image from the visual matches tab.

scraping Google Lens - Visual Matches section

Scrape the product tab from Google Lens

Again, we'll use the same method. This time, we use type=products to scrape the products section.

scraping Google Lens - Products tab section

As you can see, the products tab can include additional information for an online shop like link, source, or price. It's perfect if you're looking for specific product information.

References

Build an Image search engine with upload image capability:

Building an Image Search Engine app with Google Lens API
Let’s learn how to build a simple Google Lens clone using Google Lens API. We’ll learn how to upload the image and use it as a search method before returning all the visual matches.

Google Lens integration with n8n

Uploading Images and Searching with Google Lens via SerpApi
In this tutorial, we’ll build an automation that identifies an item using visual search. By leveraging Google Lens (via SerpApi) for image recognition, you can quickly determine the exact name of a card or collectible.

Bing also offers a "reverse image' search. Here is how to scrape Bing reverse image results:

How to Scrape Bing Reverse Image Results
In previous blog posts, we scraped similar images with Google and Yandex. In this blog post, I’m happy to guide you to scrape similar images with Bing Reverse Image API. Bing Visual Search allows users to upload images or paste image URL into the search bar to find more information