> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zenrows.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Using the Google Search Results API

> Scrape Google search results with the ZenRows SERP API. Extract organic rankings, paid ads, rich snippets, and structured search data.

The Google Search SERP API enables seamless extraction of search engine results from Google, providing structured search results with rich metadata. This API allows users to retrieve search rankings, advertisements, organic results, and other relevant details efficiently, making it an essential tool for SEO analysis, market research, and competitive intelligence.

## Key Features

* Extract organic search result details, including:
  * Title, description, and URL.
  * Ranking position in the search results.
* Capture paid advertisements (Google Ads) when present.
* Support for pagination to navigate multiple pages of search results.
* Obtain localized search results by specifying language and region settings.

## Supported Query Parameters

| PARAMETER   | TYPE           | DEFAULT | DESCRIPTION                                                                                                                |
| ----------- | -------------- | ------- | -------------------------------------------------------------------------------------------------------------------------- |
| **url**     | `string <uri>` |         | The full Google Search URL for which results should be extracted. Example: `https://www.google.com/search?q=web+scraping`. |
| **tld**     | `string`       | `.com`  | The top-level domain of the Google website. Supported examples: `.com`, `.ca`, `.co.uk`, ...                               |
| **country** | `string`       |         | The originating country for the search. Example: `country=es`.                                                             |

## How to Use

To extract Google search results, make a request to the API endpoint with your desired query parameters:

```bash theme={null}
https://serp.api.zenrows.com/v1/targets/google/search?url={url}&apikey=YOUR_ZENROWS_API_KEY
```

### Example

```bash cURL theme={null}
curl "https://serp.api.zenrows.com/v1/targets/google/search/{query}?apikey=YOUR_ZENROWS_API_KEY"
```

<Note>`{query}` should be URL-encoded.</Note>

<RequestExample>
  ```python Python theme={null}
  # pip install requests
  import requests
  import urllib.parse

  query = "web scraping"  # Example query
  encoded_query = urllib.parse.quote(query)
  api_endpoint = f"https://serp.api.zenrows.com/v1/targets/google/search/{encoded_query}"
  params = {
      "apikey": "YOUR_ZENROWS_API_KEY",
  }
  response = requests.get(api_endpoint, params=params)
  print(response.text)
  ```

  ```javascript NodeJS theme={null}
  // npm install axios
  const axios = require('axios');

  const query = "web scraping"; // Example query
  const encodedQuery = encodeURIComponent(query);
  const apikey = 'YOUR_ZENROWS_API_KEY';
  const api_endpoint = `https://serp.api.zenrows.com/v1/targets/google/search/${encodedQuery}`;

  axios
      .get(api_endpoint, {
          params: { apikey },
      })
      .then((response) => console.log(response.data))
      .catch((error) => console.log(error));
  ```

  ```java Java theme={null}
  import org.apache.hc.client5.http.fluent.Request;
  import org.apache.hc.core5.net.URIBuilder;
  import java.net.URI;
  import java.net.URLEncoder;
  import java.nio.charset.StandardCharsets;

  public class ZRRequest {
      public static void main(final String... args) throws Exception {
          String query = "web scraping"; // Example query
          String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8.toString());
          String api_endpoint = "https://serp.api.zenrows.com/v1/targets/google/search/" + encodedQuery;
          String apikey = "YOUR_ZENROWS_API_KEY";

          URI uri = new URIBuilder(api_endpoint)
              .addParameter("apikey", apikey)
              .build();

          String response = Request.get(uri)
              .execute().returnContent().asString();

          System.out.println(response);
      }
  }
  ```

  ```php PHP theme={null}
  <?php
  $query = "web scraping"; // Example query
  $encoded_query = urlencode($query);
  $api_endpoint = "https://serp.api.zenrows.com/v1/targets/google/search/" . $encoded_query;
  $apikey = 'YOUR_ZENROWS_API_KEY';
  $params = [
      'apikey' => $apikey,
  ];

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $api_endpoint . '?' . http_build_query($params));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

  $response = curl_exec($ch);
  echo $response . PHP_EOL;
  curl_close($ch);
  ```

  ```go Go theme={null}
  package main

  import (
      "fmt"
      "io/ioutil"
      "log"
      "net/http"
      "net/url"
  )

  func main() {
      query := "web scraping" // Example query
      encodedQuery := url.PathEscape(query)
      api_endpoint := "https://serp.api.zenrows.com/v1/targets/google/search/" + encodedQuery
      apikey := "YOUR_ZENROWS_API_KEY"
      params := url.Values{}
      params.Add("apikey", apikey)

      resp, err := http.Get(api_endpoint + "?" + params.Encode())
      if err != nil {
          log.Fatalln(err)
      }
      defer resp.Body.Close()

      body, err := ioutil.ReadAll(resp.Body)
      if err != nil {
          log.Fatalln(err)
      }

      fmt.Println(string(body))
  }
  ```

  ```ruby Ruby theme={null}
  # gem install faraday
  require 'faraday'
  require 'cgi'

  query = "web scraping" # Example query
  encoded_query = CGI.escape(query)
  api_endpoint = "https://serp.api.zenrows.com/v1/targets/google/search/#{encoded_query}"
  apikey = 'YOUR_ZENROWS_API_KEY'

  conn = Faraday.new(url: api_endpoint) do |f|
    f.params = {
      apikey: apikey
    }
  end

  response = conn.get

  puts response.body
  ```
</RequestExample>

<ResponseExample>
  ```json Response Example theme={null}
  {
    "organic_results": [
      {
        "title": "What is Web Scraping? A Beginner's Guide - ZenRows",
        "link": "https://www.zenrows.com/web-scraping-guide",
        "snippet": "Learn the fundamentals of web scraping, how it works, and its applications."
      },
      {
        "title": "Best Web Scraping Tools in 2024 - Comparison",
        "link": "https://www.example.com/best-web-scraping-tools",
        "snippet": "A detailed comparison of the top web scraping tools available today."
      }
    ],
    "ad_results": [
      {
        "title": "Top Web Scraping API - Free Trial Available",
        "link": "https://www.exampleads.com/webscraping",
        "snippet": "Get structured data from any website effortlessly with our advanced API."
      }
    ]
  }
  ```
</ResponseExample>

## Troubleshooting and FAQs

<Accordion title="Can I extract search results for a specific country or domain?">
  Yes, you can use the location parameter to target a specific geographic region and the TLD parameter to specify the domain of the search results.
</Accordion>

<Accordion title="What does the query parameter represent?">
  The `query` parameter is the search term you want to look up on Google's website. Make sure to URL-encode the query string (e.g., `Wireless Headphones` becomes `Wireless+Headphones`).
</Accordion>
