• Stars
    star
    56
  • Rank 511,965 (Top 11 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Search Results GoLang API

Google Search Results GoLang API

test

This Golang package enables to scrape and parse results from Google, Bing, Baidu, Yahoo, Yandex, Ebay, Google Schoolar and more using SerpApi.

This project is an implementation of SerpApi in Golang 1.12 There is no dependency for this project.

This Go module is meant to scrape and parse Google results using SerpApi. The following services are provided:

SerpApi provides a script builder to get you started quickly.

An implementation example is provided here.

demo/demo.go

You take a look to our test.

test/google_seach_results_test.go

The full documentation is available here.

Installation

Go 1.10+ must be already installed.

go get -u github.com/serpapi/google-search-results-golang

Quick start

package main

import (
	"fmt"
	g "github.com/serpapi/google-search-results-golang"
)

parameter := map[string]string{
    "q":            "Coffee",
    "location":     "Portland"
}

query := NewGoogleSearch(parameter, api)
// Many search engine available: bing, yahoo, baidu, googemaps, googleproduct, googlescholar, ebay, walmart, youtube..

rsp, err := query.json()
results := rsp["organic_results"].([]interface{})
first_result := results[0].(map[string]interface{})
fmt.Println(ref["title"].(string))

This example runs a search about "coffee" using your secret api key.

The SerpApi service (backend)

  • searches on Google using the search: q = "coffee"
  • parses the messy HTML responses
  • return a standardizes JSON response
  • Format the request
  • Execute GET http request against SerpApi service
  • Parse JSON response into a deep hash Et voila..

Alternatively, you can search:

  • Bing using NewBingSearch method
  • Baidu using NewBaiduSearch method

See the playground to generate your code.

Example

Search API capability

parameter = {
  "q": "query",
  "google_domain": "Google Domain",
  "location": "Location Requested",
  "device": device,
  "hl": "Google UI Language",
  "gl": "Google Country",
  "safe": "Safe Search Flag",
  "num": "Number of Results",
  "start": "Pagination Offset",
  "api_key": "Your SERP API Key",
  "tbm": "nws|isch|shop",
  "tbs": "custom to be search criteria",
  "async": true|false,  // allow async 
  "output": "json|html" // output format
}

// api_key from https://serpapi.com/dashboard
api_key := "your personal API key"

// set search engine: google|yahoo|bing|ebay|yandex
engine := "yahoo"

// define the search search
search := NewSearch(engine, parameter, api_key)

// override an existing parameter
search.parameter["location"] = "Portland,Oregon,United States"

// search format return as raw html
data, err := search.GetHTML()

// search format returns a json
data, err := search.GetJSON()

(the full documentation)[https://serpapi.com/search-api]

Full example: [https://github.com/serpapi/google-search-results-golang/blob/master/demo/demo.go]

see below for more hands on examples.

Location API

var locationList SerpResponseArray
var err error
locationList, err = search.GetLocation("Austin", 3)

if err != nil {
  log.Println(err)
}
log.Println(locationList)

rsp contains the first 3 location matching Austin (Texas, Texas, Rochester)

Search Archive API

Run a search then get search result from the archive using the search archive API.

parameter := map[string]string{
  "q":        "Coffee",
  "location": "Portland"
  }

search := NewGoogleSearch(parameter, "your user key")
rsp, err := search.GetJSON()

if err != nil {
  log.Println("unexpected error", err)
}

searchID := rsp["search_metadata"].(map[string]interface{})["id"].(string)
searchArchive, err := search.GetSearchArchive(searchID)
if err != nil {
  log.Println(err)
  return
}

searchIDArchive := searchArchive["search_metadata"].(map[string]interface{})["id"].(string)
if searchIDArchive != searchID {
  log.Println("search_metadata.id do not match", searchIDArchive, searchID)
}

log.Println(searchIDArchive)

it prints the search ID from the archive.

Account API

var data SearchResult
var err error
data, err = search.GetAccount()

if err != nil {
  log.Println(err)
  return
}
log.Println(data)

data contains the account information.

Example by specification

We love true open source, continuous integration and Test Drive Development (TDD). We are using "go test" to test our infrastructure around the clock to achieve the best QoS (Quality Of Service).

The directory test/ includes specification/examples.

To run the test from bash using make

export API_KEY="your secret key"
make test

Error management

This library follows the basic error management solution provided by Go. A simple error is returned in case something goes wrong. The error wraps a simple error message.

Change log

  • 3.2
    • add naver search
    • add apple store search
  • 3.1
    • Add home depot search engine
  • 3.0
    • Naming convention change.
    • Rename Client to Search
    • Fix lint issue
    • Add walmart and youtube
  • 2.1
    • Add support for Yandex, Ebay, Yahoo
    • create HTTP search only once per SerpApiClient
  • 2.0 Rewrite fully the implementation to be more scalable in order to support multiple engines.
  • 1.3 Add support for Bing and Baidu
  • 1.2 Export NewGoogleSearch outside of the package.

Conclusion

SerpApi supports mutiple search engines and subservices all available for this Golang search.

For example: Using Google search. To enable a type of search, the field tbm (to be matched) must be set to:

  • isch: Google Images API.
  • nws: Google News API.
  • shop: Google Shopping API.
  • any other Google service should work out of the box.
  • (no tbm parameter): regular Google search.

The field tbs allows to customize the search even more.

The full documentation is available here.

Contributing

Contributions are welcome, feel to submit a pull request!

To run the tests:

make test

More Repositories

1

google-search-results-python

Google Search Results via SERP API pip Python Package
Python
521
star
2

awesome-seo-tools

Curated list of awesome SEO tools
HTML
171
star
3

turbo_tests

Run RSpec tests on multiple cores. Like parallel_tests but with incremental summarized output. Originally extracted from the Discourse and Rubygems source code.
Ruby
155
star
4

nokolexbor

High-performance HTML5 parser for Ruby based on Lexbor, with support for both CSS selectors and XPath.
C
154
star
5

clauneck

A tool for scraping emails, social media accounts, and much more information from websites using Google Search Results.
Ruby
136
star
6

google-search-results-nodejs

SerpApi client library for Node.js. Previously: Google Search Results Node.js.
JavaScript
68
star
7

google-search-results-php

Google Search Results PHP API via Serp Api
PHP
52
star
8

google-search-results-ruby

Google Search Results via SERP API Ruby Gem
Ruby
49
star
9

public-roadmap

Public roadmap for SerpApi, LLC (https://serpapi.com)
43
star
10

serpapi-javascript

Scrape and parse search engine results using SerpApi.
TypeScript
41
star
11

serpapi-python

an official Python client library for SerpApi.
Python
36
star
12

google-search-results-java

Google Search Results JAVA API via SerpApi
Java
34
star
13

review-analyzer

A Chrome Extension for extracting valuable insights from reviews, generating concise summaries, sentiment analysis, and keyword extraction
JavaScript
31
star
14

serapis-ai-image-classifier

Automatic Image Classification from SERP Data
Python
25
star
15

google-reviews-analyzer

Uses LLM to summarize reviews of a business
JavaScript
24
star
16

Wander

Replicate Wanderlust demo that shown in OpenAI Dev Day
JavaScript
22
star
17

code-challenge

SerpApi code challenge
HTML
15
star
18

google-local-results-ai-parser

A ruby gem to extract structured data from Google Local Search Results using the serpapi/bert-base-local-results model, enabling parsing, classification, and information extraction from English HTML content.
Ruby
14
star
19

google-local-results-ai-server

A server code for serving BERT-based models for text classification. It is designed by SerpApi for heavy-load prototyping and production tasks, specifically for the implementation of the google-local-results-ai-parser gem.
Python
12
star
20

automatic-images-classifier-generator

Generate machine learning models fully automatically to clasiffiy any images using SERP data
Python
11
star
21

uule_converter

A Ruby library for encoding and decoding UULE parameters in Google search URLs using coordinates
Ruby
9
star
22

google-search-results-dotnet

Google Search Results via SERP API DotNet Package
C#
8
star
23

Auto-GPT-SerpApi-Plugin

An Auto-GPT Plugin that connects SerpApi to Auto-GPT
Python
7
star
24

serpapi-search-swift

Scrape and parse search resuts from Google, Bing, Baidu, Yandex, Yahoo, Home depot, Ebay and more.. using [SerpApi](https://serpapi.com).
Ruby
6
star
25

google-maps-pb-decoder

Google Maps pb (i.e., protobuf) parameter decoder.
Ruby
5
star
26

google-apps-script

Google Apps Scripts for Google Sheet to integrate SerpApi
JavaScript
4
star
27

ved_decoder

VedDecoder is a decoder for the Google ved parameter
Ruby
3
star
28

serpapi-search-rust

Search results in Rust powered by SerpApi.com
Rust
3
star
29

serpapi-ruby

Official Ruby wrapper for SerpApi HTTP endpoints
Ruby
3
star
30

seo-rank-tracker

TypeScript
2
star
31

serpapi-rust

Scrape any major search engine from our easy, fast, scalable and feature rich API powered by SerpApi
Rust
2
star
32

google-sheet-addon-guide

Documentation for Google Sheet Add-on for SerpApi
2
star
33

serpapi-java

Official Java wrapper for SerpApi HTTP endpoints
Java
2
star
34

test-knowledge-graph-desktop

Tests for Google Knowledge Graph API
Ruby
1
star
35

test-bing-organic-results-desktop

Tests for SerpApi desktop Bing organic results https://serpapi.com/bing-organic-results
Ruby
1
star
36

serpapi-golang

SerpApi client implementation in Golang
Go
1
star
37

serpapi-dotnet

SerpApi Client library for dotnet 5 and 6
C#
1
star
38

test-product-results

Test Google Product page results
Ruby
1
star
39

test-bing-organic-results-mobile

Tests for SerpApi mobile Bing organic results https://serpapi.com/organic-results
1
star
40

test-shopping-results-desktop

Test shopping results for SerpApi desktop
Ruby
1
star
41

test-scholar-organic-results

Test Google Scholar organic results for SerpApi
Ruby
1
star
42

test-bing-knowledge-graph-desktop

Tests for SerpApi desktop Bing knowledge graph results https://serpapi.com/bing-knowledge-graph
Ruby
1
star
43

test-organic-results-desktop

Tests for SerpApi desktop organic results
Ruby
1
star
44

test-product-reviews-results

Ruby
1
star
45

serpapi-search-cpp

Library to search on Google, Bing, HomeDepot, Baidu, Yandex and more using SerpApi written in C++.
C++
1
star
46

test-organic-results-mobile

Tests for SerpApi mobile organic results
Ruby
1
star
47

test-product-specs-results

Ruby
1
star
48

test-related-questions-desktop

Test related questions "People also ask" block
Ruby
1
star
49

serpapi-vscode-snippets

SerAPI Snippets for VSCode - Scrape search engine results
JavaScript
1
star
50

test-images-results-desktop

Tests for SerpApi Images results for desktop (beta)
Ruby
1
star
51

showcase-pot-stock-map

showcase market research with serpapi to track pot stock
JavaScript
1
star
52

test-product-sellers-results

Ruby
1
star
53

test-google-direct-answers-box-api

Tests for Google Direct Answers Box API
Ruby
1
star
54

test-bing-ad-results-desktop

Tests for SerpApi desktop Bing ad results https://serpapi.com/bing-ads
Ruby
1
star
55

spec-builder

Run all tests for SerpApi.com
Ruby
1
star
56

hash-json-path

HashJsonPath is a simple gem to access hash and set hash value using json path
Ruby
1
star
57

showcase-serpapi-tensorflow-keras-image-training

Tensorflow / Keras training a network to recognize Apple logo versus a real Apple fruit
Python
1
star
58

test-video-results

Test video result for mobile and desktop
Ruby
1
star
59

test-news-results-desktop

Test news results for SerpApi desktop
Ruby
1
star
60

serpapi-wallstreet-analysis

Analyze company business using Google search powered by SerpApi.com
Python
1
star