DuckDuckGo Image Scraper

A C# (.NET) approach for retrieving image URLs

Most search engines provide no official API for scraping images, and DuckDuckGo is no different—no public image API exists to date. If you need a fast way to programmatically gather images from searches, this API can help. By parsing a small portion of DuckDuckGo's HTML and subsequently sending a follow-up query to its i.js endpoint, you can build a list of images relevant to a target keyword. This project demonstrates how to structure the requests and parse their responses in C#.

Example: Searching 'dogs' on DuckDuckGo
Inspecting the VQD in the webpage HTML
Inspecting JSON data returned by i.js

Quack! What's the Deal?

The heart of the approach is acquiring a special VQD parameter. Each time you search for something on DuckDuckGo—e.g., "dogs"—the site generates a unique VQD token. When you request images via duckduckgo.com/i.js, DuckDuckGo expects you to include this VQD in the query string. This ensures the site serves you the correct set of results without any errors- so we'll need two requests to get the images we want.

Two Requests

  1. Initial: Load duckduckgo.com/?q=dogs, parse the HTML response, and locate the VQD token. We do this via an HTML parser.
  2. Second: Call duckduckgo.com/i.js with your search term (e.g., "dogs"), the VQD, and other parameters (geolocation, language, or SafeSearch). The endpoint responds with JSON describing relevant images—usually containing 100 results on the first page.

Each unique query or keyword demands a fresh VQD, so be sure you re-extract that VQD every time you switch from "dogs" to "cats," or any other search term. Reusing an old VQD token or not requesting it properly will give you incomplete or invalid results.

Pseudocode

void makeImageList() {
  // 1. Obtain the VQD from your first request 
  string vqd = GetVQD("dogs");

  // 2. Pass the VQD into a second request to duckduckgo.com/i.js
  List<string> imageUrls = GetImageList("duckduckgo.com/i.js?vqd=" + vqd);

  // 3. You now have a list of image URLs for 'dogs'!
}

string GetVQD(string keyword) {
  // e.g., request "duckduckgo.com/?q=keyword"
  // parse the HTML to find "vqd"
  return vqd;
}

List<string> GetImageList(string urlWithVqd) {
  // request "duckduckgo.com/i.js" with the relevant parameters
  // parse JSON or raw text to extract the image URLs
  return urls;
}

In a .NET application, you can leverage HttpClient to make these requests. Ensure you set the appropriate headers—like a user-agent—to mimic how a regular browser approaches DuckDuckGo. Then, parse the HTML or JSON responses to find the VQD token and the actual image links. Since this is unofficial, be prepared to adapt if DuckDuckGo modifies their internal parameters down the line!