Skip to main content

Scrape direct image URLs from Bing, DuckDuckGo, Yandex, and Google

Project description

imgapi

Scrape direct image URLs from Bing, DuckDuckGo, Yandex, and Google. Returns links like https://example.com/photo.jpg — not thumbnails, not base64, not search pages.


Install

Python (pip)

pip install imgapi
scrapling install   # one-time: downloads stealth browser (~200 MB)

Node.js (npm)

npm install imgapi
# browser is installed automatically via postinstall

Python usage

Import

from imgapi import image_search, random_image

image_search(query, engines=None, n=10)

Search for images matching a query. Returns a list of direct image URLs.

Parameters

Parameter Type Default Description
query str required Search term, e.g. "golden retriever"
engines list[str] | None ["bing", "ddg"] Engines to query, in priority order
n int 10 Maximum number of URLs to return

Returns list[str] — direct image URLs, up to n items.

Examples

from imgapi import image_search

# Default: Bing first, DDG fills the rest
urls = image_search("sunset", n=10)

# Specific engine only
urls = image_search("cat", engines=["bing"], n=5)

# Multiple engines, tries each until n results collected
urls = image_search("dog", engines=["bing", "ddg"], n=20)

# With proxy (for Google / Yandex — see Engine notes below)
urls = image_search("flowers", engines=["google"], n=5)

random_image(query, engines=None)

Returns a single random direct image URL for the query.

Parameters

Parameter Type Default Description
query str required Search term
engines list[str] | None ["bing", "ddg"] Engines to query

Returns str | None — one direct image URL, or None if no results.

Examples

from imgapi import random_image

url = random_image("abstract art")
# → "https://upload.wikimedia.org/wikipedia/commons/..."

url = random_image("mountain", engines=["bing"])
# → "https://images.pexels.com/photos/.../mountain.jpg"

Engines

Engine Key Returns Notes
Bing "bing" Full-size original URLs ✅ Recommended. Fast, reliable, high quality.
DuckDuckGo "ddg" Bing CDN thumbnails ✅ Works. Uses Bing's index — thumbnails are valid images.
Yandex "yandex" Full-size originals ⚠️ May be geo-blocked (Russia traffic). Works with VPN.
Google "google" Full-size originals ⚠️ Requires residential proxy. Blocked by reCAPTCHA on most IPs.

Recommended: use ["bing"] or ["bing", "ddg"] for reliability.

Using Google or Yandex with a proxy

Configure before calling any function:

from scrapling.fetchers import StealthyFetcher

StealthyFetcher.configure()  # global config
# then pass proxy per-call via engines' internal fetcher (see below)

Proxy support per-call is on the roadmap.


Node.js usage

Import

const { imageSearch, randomImage, closeBrowser } = require("imgapi");

imageSearch(query, options?)

Parameters

Parameter Type Default Description
query string required Search term
options.engines string[] ["bing","ddg"] Engines in priority order
options.n number 10 Max URLs to return

Returns Promise<string[]>

const { imageSearch } = require("imgapi");

// Default engines
const urls = await imageSearch("sunset", { n: 10 });

// Specific engine
const urls = await imageSearch("cat", { engines: ["bing"], n: 5 });

// Multiple engines
const urls = await imageSearch("dog", { engines: ["bing", "ddg"], n: 20 });

randomImage(query, options?)

Parameters

Parameter Type Default Description
query string required Search term
options.engines string[] ["bing","ddg"] Engines to query

Returns Promise<string|null>

const { randomImage } = require("imgapi");

const url = await randomImage("abstract art");
console.log(url); // "https://example.com/image.jpg"

closeBrowser()

Call when done to shut down the browser instance cleanly.

const { imageSearch, closeBrowser } = require("imgapi");

const urls = await imageSearch("mountain");
console.log(urls);
await closeBrowser();

How it works

Each engine scrapes the search results page using a stealth headless browser (StealthyFetcher from Scrapling) to bypass bot detection.

Image URLs are extracted from structured data embedded in the page — not from thumbnails or base64 blobs:

  • Bing: parses murl from the JSON m attribute on result links (a.iusc[m])
  • DDG: extracts real URL from the u= parameter inside DDG's CDN proxy URLs
  • Yandex: parses img_href from data-bem JSON on result elements
  • Google: extracts "ou":"..." fields (original URL) from embedded script blobs

The singleton fetcher reuses the browser session across calls — the browser starts once and stays open, making repeated calls faster.


Project structure

imgapi/
  __init__.py        # exports image_search, random_image
  _fetcher.py        # StealthyFetcher singleton
  search.py          # image_search + random_image logic
  engines/
    bing.py
    ddg.py
    yandex.py
    google.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

imgsearch_api-0.1.0.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

imgsearch_api-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file imgsearch_api-0.1.0.tar.gz.

File metadata

  • Download URL: imgsearch_api-0.1.0.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for imgsearch_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c172f90c6538281d0e89a3958ba5f9a10dbb4e9d4763b40c0ee45e02888ac43f
MD5 0386c1ac0abe5e4d854e3dbce21c52f7
BLAKE2b-256 cb8299f552d7df326616030bbe93f4d53fbd32bfc41b481f6b898a39beb26b34

See more details on using hashes here.

File details

Details for the file imgsearch_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: imgsearch_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for imgsearch_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5b110d99f82643b37612d6a0b9bfa471c4e5a580c44c3ae923e93f17af4bc451
MD5 eec223a046bbf379fc2f0b9bc80a6e3f
BLAKE2b-256 0699803312e889afdb50cb7bc15251b407ea976c99393e968174052cda54f210

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page