ChartQuery

Recopilar imágenes de Google

Descarga y cataloga URLs de imágenes para cualquier consulta de búsqueda usando la API de Autom — útil para construir datasets, investigación visual o auditorías de activos de la competencia.

Descripción general

Este tutorial muestra cómo recopilar URLs de imágenes, títulos y dimensiones de Google Images para una consulta dada. Cada resultado incluye la URL directa de la imagen, la página donde se encontró, el dominio de origen y las dimensiones en píxeles.

Prerrequisitos

  • Una clave de API de Autom — consigue una en app.autom.dev
  • Instala las dependencias para tu lenguaje:
pip install requests

Sin dependencias adicionales — usa la API nativa fetch (Node 18+).

Extensión curl habilitada (activa por defecto).

Sin dependencias adicionales — usa net/http (Go 1.18+).

Sin dependencias adicionales — usa java.net.http (Java 11+).

Sin dependencias adicionales — usa System.Net.Http (.NET 6+).

# Cargo.toml
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }
serde_json = "1"

Pasos

Busca imágenes

Llama a GET /v1/google/images con el parámetro q.

import requests

API_KEY = "YOUR_API_KEY"

response = requests.get(
    "https://api.autom.dev/v1/google/images",
    headers={"x-api-key": API_KEY},
    params={"q": "estación de carga de coches eléctricos", "gl": "es", "hl": "es"},
)
data = response.json()
const API_KEY = "YOUR_API_KEY";

const params   = new URLSearchParams({ q: "estación de carga de coches eléctricos", gl: "es", hl: "es" });
const response = await fetch(`https://api.autom.dev/v1/google/images?${params}`, {
  headers: { "x-api-key": API_KEY },
});
const data = await response.json();
<?php
$apiKey = "YOUR_API_KEY";
$params = http_build_query(["q" => "estación de carga de coches eléctricos", "gl" => "es", "hl" => "es"]);

$ch = curl_init("https://api.autom.dev/v1/google/images?{$params}");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-api-key: {$apiKey}"]);
$data = json_decode(curl_exec($ch), true);
curl_close($ch);
package main

import (
    "encoding/json"
    "io"
    "net/http"
    "net/url"
)

func main() {
    params := url.Values{"q": {"estación de carga de coches eléctricos"}, "gl": {"es"}, "hl": {"es"}}
    req, _ := http.NewRequest("GET", "https://api.autom.dev/v1/google/images?"+params.Encode(), nil)
    req.Header.Set("x-api-key", "YOUR_API_KEY")

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)

    var data map[string]any
    json.Unmarshal(body, &data)
}
import java.net.URI;
import java.net.http.*;

var client  = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
    .uri(URI.create("https://api.autom.dev/v1/google/images?q=estaci%C3%B3n+carga+coches&gl=es&hl=es"))
    .header("x-api-key", "YOUR_API_KEY")
    .GET().build();

var response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
using System.Net.Http;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");

var body = await client.GetStringAsync(
    "https://api.autom.dev/v1/google/images?q=estaci%C3%B3n+carga+coches&gl=es&hl=es");
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let data = reqwest::Client::new()
        .get("https://api.autom.dev/v1/google/images")
        .header("x-api-key", "YOUR_API_KEY")
        .query(&[("q", "estación de carga de coches eléctricos"), ("gl", "es"), ("hl", "es")])
        .send().await?.json::<serde_json::Value>().await?;

    println!("{:#?}", data);
    Ok(())
}

Examina los resultados de imágenes

Cada elemento en images tiene url (imagen directa), link (página de origen), title, domain, source, image_width e image_height.

for img in data.get("images", []):
    print(f"[{img['position']}] {img['title']}")
    print(f"  Imagen  : {img['url']}")
    print(f"  Fuente  : {img['source']}{img['image_width']}x{img['image_height']}px\n")
for (const img of data.images ?? []) {
  console.log(`[${img.position}] ${img.title}`);
  console.log(`  Imagen  : ${img.url}`);
  console.log(`  Fuente  : ${img.source} — ${img.image_width}x${img.image_height}px\n`);
}
foreach ($data["images"] ?? [] as $img) {
    echo "[{$img['position']}] {$img['title']}\n";
    echo "  Imagen  : {$img['url']}\n";
    echo "  Fuente  : {$img['source']} — {$img['image_width']}x{$img['image_height']}px\n\n";
}
for _, r := range data["images"].([]any) {
    img := r.(map[string]any)
    fmt.Printf("[%.0f] %s\n  Imagen  : %s\n  Fuente  : %s%.0fx%.0fpx\n\n",
        img["position"], img["title"], img["url"],
        img["source"], img["image_width"], img["image_height"])
}
import org.json.*;

var images = new JSONObject(response.body()).getJSONArray("images");
for (int i = 0; i < images.length(); i++) {
    var img = images.getJSONObject(i);
    System.out.printf("[%d] %s%n  Imagen  : %s%n  Fuente  : %s — %dx%dpx%n%n",
        img.getInt("position"), img.getString("title"),
        img.getString("url"), img.getString("source"),
        img.getInt("image_width"), img.getInt("image_height"));
}
using System.Text.Json;

var images = JsonDocument.Parse(body).RootElement.GetProperty("images").EnumerateArray();
foreach (var img in images)
{
    Console.WriteLine($"[{img.GetProperty("position")}] {img.GetProperty("title")}");
    Console.WriteLine($"  Imagen  : {img.GetProperty("url")}");
    Console.WriteLine($"  Fuente  : {img.GetProperty("source")}{img.GetProperty("image_width")}x{img.GetProperty("image_height")}px\n");
}
if let Some(images) = data["images"].as_array() {
    for img in images {
        println!("[{}] {}", img["position"], img["title"].as_str().unwrap_or(""));
        println!("  Imagen  : {}", img["url"].as_str().unwrap_or(""));
        println!("  Fuente  : {} — {}x{}px\n",
            img["source"].as_str().unwrap_or(""), img["image_width"], img["image_height"]);
    }
}

Construye un catálogo filtrado por tamaño mínimo

Filtra las miniaturas y guarda solo las imágenes de alta resolución.

import csv, requests

API_KEY   = "YOUR_API_KEY"
QUERY     = "estación de carga de coches eléctricos"
MIN_WIDTH = 800

def fetch_images(query: str, pages: int = 2) -> list:
    results = []
    for page in range(1, pages + 1):
        r = requests.get("https://api.autom.dev/v1/google/images",
            headers={"x-api-key": API_KEY},
            params={"q": query, "gl": "es", "hl": "es", "page": page})
        results.extend(r.json().get("images", []))
    return results

large = [img for img in fetch_images(QUERY) if img.get("image_width", 0) >= MIN_WIDTH]

with open("image_catalog.csv", "w", newline="") as f:
    writer = csv.DictWriter(f, fieldnames=["position", "title", "url", "source", "image_width", "image_height"])
    writer.writeheader()
    writer.writerows(large)

print(f"Guardadas {len(large)} imágenes de alta resolución en image_catalog.csv")
import { writeFileSync } from "fs";

const API_KEY   = "YOUR_API_KEY";
const MIN_WIDTH = 800;

async function fetchImages(query: string, pages = 2): Promise<any[]> {
  const all: any[] = [];
  for (let page = 1; page <= pages; page++) {
    const params = new URLSearchParams({ q: query, gl: "es", hl: "es", page: String(page) });
    const res    = await fetch(`https://api.autom.dev/v1/google/images?${params}`, {
      headers: { "x-api-key": API_KEY },
    });
    all.push(...((await res.json()).images ?? []));
  }
  return all;
}

const images = await fetchImages("estación de carga de coches eléctricos");
const large  = images.filter(img => (img.image_width ?? 0) >= MIN_WIDTH);
writeFileSync("image_catalog.json", JSON.stringify(large, null, 2));
console.log(`Guardadas ${large.length} imágenes de alta resolución en image_catalog.json`);
<?php
$apiKey   = "YOUR_API_KEY";
$query    = "estación de carga de coches eléctricos";
$minWidth = 800;

function fetchImages(string $apiKey, string $query, int $pages = 2): array {
    $all = [];
    for ($page = 1; $page <= $pages; $page++) {
        $params = http_build_query(["q" => $query, "gl" => "es", "hl" => "es", "page" => $page]);
        $ch = curl_init("https://api.autom.dev/v1/google/images?{$params}");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ["x-api-key: {$apiKey}"]);
        $data = json_decode(curl_exec($ch), true);
        curl_close($ch);
        $all = array_merge($all, $data["images"] ?? []);
    }
    return $all;
}

$large = array_filter(fetchImages($apiKey, $query), fn($img) => ($img["image_width"] ?? 0) >= $minWidth);
file_put_contents("image_catalog.json", json_encode(array_values($large), JSON_PRETTY_PRINT));
echo "Guardadas " . count($large) . " imágenes de alta resolución en image_catalog.json\n";
package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "strconv"
)

func fetchImages(apiKey, query string, pages int) []map[string]any {
    var all []map[string]any
    for page := 1; page <= pages; page++ {
        params := url.Values{"q": {query}, "gl": {"es"}, "hl": {"es"}, "page": {strconv.Itoa(page)}}
        req, _ := http.NewRequest("GET", "https://api.autom.dev/v1/google/images?"+params.Encode(), nil)
        req.Header.Set("x-api-key", apiKey)
        resp, _ := http.DefaultClient.Do(req)
        body, _ := io.ReadAll(resp.Body)
        resp.Body.Close()

        var data map[string]any
        json.Unmarshal(body, &data)
        for _, r := range data["images"].([]any) { all = append(all, r.(map[string]any)) }
    }
    return all
}

func main() {
    images   := fetchImages("YOUR_API_KEY", "estación de carga de coches eléctricos", 2)
    var large []map[string]any
    for _, img := range images {
        if img["image_width"].(float64) >= 800 { large = append(large, img) }
    }
    b, _ := json.MarshalIndent(large, "", "  ")
    os.WriteFile("image_catalog.json", b, 0644)
    fmt.Printf("Guardadas %d imágenes de alta resolución en image_catalog.json\n", len(large))
}
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.*;
import org.json.*;

public class Main {
    public static void main(String[] args) throws Exception {
        var apiKey  = "YOUR_API_KEY";
        var query   = URLEncoder.encode("estación de carga de coches eléctricos", StandardCharsets.UTF_8);
        var client  = HttpClient.newHttpClient();
        var all     = new JSONArray();

        for (int page = 1; page <= 2; page++) {
            var url  = "https://api.autom.dev/v1/google/images?q=" + query + "&gl=es&hl=es&page=" + page;
            var req  = HttpRequest.newBuilder().uri(URI.create(url))
                .header("x-api-key", apiKey).GET().build();
            var resp = client.send(req, HttpResponse.BodyHandlers.ofString());
            var imgs = new JSONObject(resp.body()).getJSONArray("images");
            for (int i = 0; i < imgs.length(); i++) all.put(imgs.get(i));
        }

        var large = new JSONArray();
        for (int i = 0; i < all.length(); i++) {
            var img = all.getJSONObject(i);
            if (img.getInt("image_width") >= 800) large.put(img);
        }
        Files.writeString(Path.of("image_catalog.json"), large.toString(2));
        System.out.println("Guardadas " + large.length() + " imágenes de alta resolución.");
    }
}
using System.Net.Http;
using System.Text.Json;

using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");

var all = new List<JsonElement>();
for (int page = 1; page <= 2; page++)
{
    var body = await client.GetStringAsync(
        $"https://api.autom.dev/v1/google/images?q=estacion+carga+coches&gl=es&hl=es&page={page}");
    foreach (var img in JsonDocument.Parse(body).RootElement.GetProperty("images").EnumerateArray())
        all.Add(img);
}

var large = all.Where(img => img.GetProperty("image_width").GetInt32() >= 800).ToList();
File.WriteAllText("image_catalog.json", JsonSerializer.Serialize(large, new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine($"Guardadas {large.Count} imágenes de alta resolución.");
use reqwest::Client;
use serde_json::Value;
use std::fs;

async fn fetch_images(client: &Client, api_key: &str, query: &str, pages: u32) -> Vec<Value> {
    let mut all = Vec::new();
    for page in 1..=pages {
        let data = client.get("https://api.autom.dev/v1/google/images")
            .header("x-api-key", api_key)
            .query(&[("q", query), ("gl", "es"), ("hl", "es"), ("page", &page.to_string())])
            .send().await.unwrap().json::<Value>().await.unwrap();
        if let Some(imgs) = data["images"].as_array() { all.extend(imgs.clone()); }
    }
    all
}

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let client = Client::new();
    let images = fetch_images(&client, "YOUR_API_KEY", "estación de carga de coches eléctricos", 2).await;
    let large: Vec<&Value> = images.iter()
        .filter(|img| img["image_width"].as_i64().unwrap_or(0) >= 800)
        .collect();
    fs::write("image_catalog.json", serde_json::to_string_pretty(&large).unwrap()).unwrap();
    println!("Guardadas {} imágenes de alta resolución.", large.len());
    Ok(())
}

El campo url en cada resultado es el enlace directo al archivo de imagen. Verifica siempre que tienes los derechos para usar una imagen antes de incluirla en un dataset o producto.

En esta página