Zum Hauptinhalt springen

Google-Scraper mit Olostep

Diese Anleitung zeigt, wie du die Olostep-API verwenden kannst, um Google-Suchergebnisse zu scrapen und in strukturierte JSON-Daten zu parsen. Dies ist besonders nützlich für die Automatisierung von Rechercheaufgaben, das Sammeln von Wettbewerbsinformationen oder das Erstellen von Anwendungen, die Suchdaten benötigen.

Funktionsweise

Das folgende Javascript-Beispiel zeigt, wie du nach einer LinkedIn-Profil-URL einer bestimmten Person (Patrick Collison) mit Google-Suche und Olosteps Google-Suchparser @olostep/google-search suchen kannst.
async function scrapeGoogleSearch(apiKey, query = "site%3Alinkedin.com+Patrick+Collison") {
  const endpoint = "https://api.olostep.com/v1/scrapes";

  const payload = {
    "formats": ["json"],
    "parser": {"id": "@olostep/google-search"},
    "url_to_scrape": `https://www.google.com/search?q=${encodeURIComponent(query)}&gl=us&hl=en`,
    "wait_before_scraping": 0,
  };

  const headers = {
    "Authorization": `Bearer ${apiKey}`,
    "Content-Type": "application/json"
  };

  try {
    const response = await fetch(endpoint, {
      method: "POST",
      headers: headers,
      body: JSON.stringify(payload)
    });

    const data = await response.json();
    console.log(JSON.stringify(data, null, 4));
    return data;
  } catch (error) {
    console.error("Error:", error);
    throw error;
  }
}

// Ersetze <API_KEY> durch deinen tatsächlichen Olostep-API-Schlüssel
scrapeGoogleSearch("<API_KEY>");

Antwortformat

Wenn du eine Anfrage an die Olostep-API mit dem Google-Suchparser stellst, erhältst du eine JSON-Antwort wie das folgende Beispiel:
{
    "id": "scrape_f2xghz17kt",
    "object": "scrape",
    "created": 1742679301,
    "metadata": {},
    "retrieve_id": "f2xghz17kt",
    "url_to_scrape": "https://www.google.com/search?q=site%253Alinkedin.com%2BPatrick%2BCollison&gl=us&hl=en",
    "result": {
        "html_content": null,
        "markdown_content": null,
        "text_content": null,
        "json_content": "{\"searchParameters\":{\"type\":\"search\",\"engine\":\"google\",\"q\":\"site:linkedin.com Patrick Collison\"},\"knowledgeGraph\":{\"description\":\"Experience. Stripe Graphic · Stripe. -. Education. Massachusetts Institute of Technology Graphic · Massachusetts Institute of Technology. 2006 - 2010 ...\"},\"organic\":[{\"title\":\"Patrick Collison - Stripe\",\"link\":\"https://www.linkedin.com/in/patrickcollison\",\"position\":1,\"snippet\":\"Experience. Stripe Graphic · Stripe. -. Education. Massachusetts Institute of Technology Graphic · Massachusetts Institute of Technology. 2006 - 2010 ...\",\"meta\":\"10.8K+ followers\"},{\"title\":\"The Stripe Story: How Patrick Collison Revolutionized ...\",\"link\":\"https://www.linkedin.com/pulse/stripe-story-how-patrick-collison-revolutionized-online-anshuman-jha-jzzic\",\"position\":2,\"snippet\":\"The Early Years: A Genius in the Making. Patrick Collison wasn't just bright—he was a supernova. By age 10, he'd devoured university-level math ...\"},{\"title\":\"In 2005, Patrick Collison was a 16-year-old winning ...\",\"link\":\"https://www.linkedin.com/posts/itselanagold_in-2005-patrick-collison-was-a-16-year-old-activity-7308533537576497154-w5vC\",\"position\":3,\"snippet\":\"In 2005, Patrick Collison was a 16-year-old winning Ireland's Young Scientist of the Year competition. By 2008, he and his younger brother ...\"},{\"title\":\"Patrick Collison on the importance of waiting a really long ...\",\"link\":\"https://www.linkedin.com/posts/the-startup-archive_patrick-collison-on-the-importance-of-waiting-activity-7286001819145707520-1mdI\",\"position\":4,\"snippet\":\"Patrick argues you should also view every person you hire as bringing along another 50 people just like them if your company is successful.\"},{\"title\":\"Tim Ferriss' Post - Patrick Collison — CEO of Stripe (#353)\",\"link\":\"https://www.linkedin.com/posts/timferriss_patrick-collison-ceo-of-stripe-353-activity-7271892372358148096--dsK\",\"position\":5,\"snippet\":\"Author of 5 #1 NYT/WSJ bestsellers, early-stage investor, host of The Tim Ferriss Show podcast (1B+ downloads), and collector of the strange.\"},{\"title\":\"Patrick Collison wanted a guide to Stripe's culture that ...\",\"link\":\"https://www.linkedin.com/posts/first-round-capital_patrick-collison-wanted-a-guide-to-stripes-activity-7304833456948097024-Tt6h\",\"position\":6,\"snippet\":\"Patrick Collison wanted a guide to Stripe's culture that convinced 50% of candidates not to join. And Eeke de Milliano was tasked with ...\"},{\"title\":\"The Collison brothers (John & Patrick) explain why Stripe is ...\",\"link\":\"https://www.linkedin.com/posts/marcelvanoost_the-collison-brothers-john-patrick-explain-activity-7301586346349850624-L-4U\",\"position\":7,\"snippet\":\"The Collison brothers (John & Patrick) explain why Stripe is better off staying Private: \\\" This is our life's work. We're not going anywhere ...\"},{\"title\":\"Stripe CEO Patrick Collison on Crafting a Culture ...\",\"link\":\"https://www.linkedin.com/posts/jennifer-chatman-8086a918_stripe-ceo-patrick-collison-on-crafting-a-activity-7231753022849085440-0RE5\",\"position\":8,\"snippet\":\"When Patrick Collison and his brother John Collison founded digital payment company Stripe in 2010, he didn't come in with “any kind of ...\"},{\"title\":\"Patrick Collison on the importance of beauty and ...\",\"link\":\"https://www.linkedin.com/posts/the-startup-archive_patrick-collison-on-the-importance-of-beauty-activity-7247935993817751552-Qt6h\",\"position\":9,\"snippet\":\"Patrick Collison on the importance of beauty and craftsmanship when building products “If Stripe is a monstrously successful business, ...\"}]}",
        "llm_extract": null,
        "screenshot_hosted_url": null,
        "html_hosted_url": null,
        "markdown_hosted_url": null,
        "json_hosted_url": "https://olostep-storage.s3.us-east-1.amazonaws.com/json_f2xghz17kt.json",
        "text_hosted_url": null,
        "links_on_page": [],
        "page_metadata": {
            "status_code": 200,
            "title": ""
        }
    }
}
Die Antwort enthält:
  • Grundlegende Anfrageninformationen: id, object, created Zeitstempel, url_to_scrape
  • Ergebnisobjekt mit URLs zum Zugriff auf verschiedene Datenformate
  • json_content mit strukturierten Suchergebnissen einschließlich:
  • searchParameters: Informationen zur Suchanfrage
  • knowledgeGraph: Detaillierte Informationen über das Suchthema (falls verfügbar)
  • organic: Liste der Suchergebnisse mit Titel, Link, Position und Snippet
  • peopleAlsoAsk: Verwandte Fragen, die Benutzer häufig suchen
  • relatedSearches: Vorgeschlagene verwandte Suchanfragen
json_content ist der Hauptteil der Antwort mit den strukturierten Suchergebnissen. Du kannst auf den JSON-Inhalt direkt aus der Antwort zugreifen oder die gehostete URL verwenden, die in der Antwort bereitgestellt wird.

Strukturierte Antwort: json_content

{
  "searchParameters": {
    "type": "search",
    "engine": "google",
    "q": "site:linkedin.com Patrick Collison"
  },
  "knowledgeGraph": {
    "description": "Experience. Stripe Graphic · Stripe. -. Education. Massachusetts Institute of Technology Graphic · Massachusetts Institute of Technology. 2006 - 2010 ..."
  },
  "organic": [
    {
      "title": "Patrick Collison - Stripe",
      "link": "https://www.linkedin.com/in/patrickcollison",
      "position": 1,
      "snippet": "Experience. Stripe Graphic · Stripe. -. Education. Massachusetts Institute of Technology Graphic · Massachusetts Institute of Technology. 2006 - 2010 ...",
      "meta": "10.8K+ followers"
    },
    {
      "title": "The Stripe Story: How Patrick Collison Revolutionized ...",
      "link": "https://www.linkedin.com/pulse/stripe-story-how-patrick-collison-revolutionized-online-anshuman-jha-jzzic",
      "position": 2,
      "snippet": "The Early Years: A Genius in the Making. Patrick Collison wasn't just bright—he was a supernova. By age 10, he'd devoured university-level math ..."
    },
    {
      "title": "In 2005, Patrick Collison was a 16-year-old winning ...",
      "link": "https://www.linkedin.com/posts/itselanagold_in-2005-patrick-collison-was-a-16-year-old-activity-7308533537576497154-w5vC",
      "position": 3,
      "snippet": "In 2005, Patrick Collison was a 16-year-old winning Ireland's Young Scientist of the Year competition. By 2008, he and his younger brother ..."
    },
    {
      "title": "The Collison brothers (John & Patrick) explain why Stripe is ...",
      "link": "https://www.linkedin.com/posts/marcelvanoost_the-collison-brothers-john-patrick-explain-activity-7301586346349850624-L-4U",
      "position": 4,
      "snippet": "The Collison brothers (John & Patrick) explain why Stripe is better off staying Private: \" This is our life's work. We're not going anywhere ..."
    },
    {
      "title": "Patrick Collison on the importance of waiting a really long ...",
      "link": "https://www.linkedin.com/posts/the-startup-archive_patrick-collison-on-the-importance-of-waiting-activity-7286001819145707520-1mdI",
      "position": 5,
      "snippet": "Patrick argues you should also view every person you hire as bringing along another 50 people just like them if your company is successful."
    },
    {
      "title": "Tim Ferriss' Post - Patrick Collison — CEO of Stripe (#353)",
      "link": "https://www.linkedin.com/posts/timferriss_patrick-collison-ceo-of-stripe-353-activity-7271892372358148096--dsK",
      "position": 6,
      "snippet": "Author of 5 #1 NYT/WSJ bestsellers, early-stage investor, host of The Tim Ferriss Show podcast (1B+ downloads), and collector of the strange."
    },
    {
      "title": "Patrick Collison on the importance of beauty and ...",
      "link": "https://www.linkedin.com/posts/the-startup-archive_patrick-collison-on-the-importance-of-beauty-activity-7247935993817751552-Qt6h",
      "position": 7,
      "snippet": "Patrick Collison on the importance of beauty and craftsmanship when building products "If Stripe is a monstrously successful business, ..."
    },
    {
      "title": "Stripe founder Patrick Collison tells the story of almost ...",
      "link": "https://www.linkedin.com/posts/the-startup-archive_stripe-founder-patrick-collison-tells-the-activity-7235977194211000321-V-Cd",
      "position": 8,
      "snippet": "Stripe founder Patrick Collison tells the story of almost naming the company PayDemon Patrick and John Collison founded Stripe in 2010 when ..."
    },
    {
      "title": "Patrick Collison created $50 billion of value as a co- ...",
      "link": "https://www.linkedin.com/posts/tom-alder_patrick-collison-created-50-billion-of-value-activity-7239241304780513281-isxK",
      "position": 9,
      "snippet": "Patrick Collison created $50 billion of value as a co-founder of Stripe. He has also built the largest carbon removal program in the world."
    }
  ]
}
Olostep bietet auch eine gehostete JSON-Datei mit den strukturierten Suchergebnissen an. Du kannst auf die JSON-Datei über das Feld json_hosted_url in der Antwort zugreifen: Wenn du auch den HTML- und Markdown-Inhalt der Suchergebnisse erhalten möchtest, kannst du diese Formate im formats-Parameter einschließen und Olostep wird sie in der Antwort zurückgeben und gehostete URLs für jedes Format bereitstellen.

Beispiel-Anwendungsszenarien

1. LinkedIn-Profile finden

Im obigen Beispiel suchen wir nach Patrick Collisons LinkedIn-Profil, indem wir die Suchanfrage site:linkedin.com Patrick Collison verwenden. Diese Technik kann verwendet werden, um professionelle Profile für jede Person zu finden.

2. Unternehmen recherchieren

Du kannst die Anfrage ändern, um nach Unternehmensinformationen zu suchen:
// Suche nach Unternehmensinformationen
scrapeGoogleSearch(apiKey, "Stripe company information revenue");

3. Nachrichtenartikel verfolgen

Finde aktuelle Nachrichten zu einem bestimmten Thema:
// Suche nach aktuellen Nachrichten über KI
scrapeGoogleSearch(apiKey, "artificial intelligence news after:2023-01-01");

4. Wettbewerbsanalyse

Überwache die Online-Präsenz von Wettbewerbern:
// Suche nach Erwähnungen von Wettbewerbern
scrapeGoogleSearch(apiKey, "\"Company X\" vs \"Company Y\" comparison");

Wichtige Hinweise

  1. Suchparameter: Die Parameter gl=us und hl=en setzen die Geolokalisierung auf die USA und die Sprache auf Englisch. Passe diese nach Bedarf an.

Fazit

Sobald du die Suchergebnisdaten hast, kannst du:
  1. Bestimmte interessante Datenpunkte parsen
  2. Die Ergebnisse in einer Datenbank speichern
  3. Eine benutzerdefinierte Suchoberfläche erstellen
  4. Aktionen basierend auf Suchergebnissen auslösen
  5. Mit anderen APIs oder Diensten integrieren
Wenn du andere Datenpunkte extrahieren oder das Suchverhalten anpassen möchtest, kontaktiere uns bitte unter ‘info@olostep.com`