DEV Community

Cover image for I Migrated from Python Scrapers to Go + SerpApi - Complete Guide published: true
Pires Aurélio
Pires Aurélio

Posted on

I Migrated from Python Scrapers to Go + SerpApi - Complete Guide published: true

I'm Pires Aurélio , a Go/Python developer from Angola. I build scrapers in production and document everything in public.

My work:

For 2 years I scraped sites with pure Python/Go. Then I hit Google. Everything broke.

This tutorial is how I solved it with Go + SerpApi.

1. Why My Python Scraper Failed on Google

My repo py-websites-scraper uses asyncio + aiohttp + readability-lxml. Great for blogs.

But for Google Jobs / Shopping:

  • CAPTCHA in 10 requests
  • 429 blocks
  • Selectors change weekly

I was spending 80% time fighting anti-bot, 20% building features. Wrong.

2. Why SerpApi + Go Is The Stack

SerpApi handles proxies, CAPTCHAs, parsing. You get clean JSON.
Go handles concurrency perfectly.

My stack now: Go + SerpApi + Gin REST API (as I teach in my blog)

3. Setup (2 minutes)


bash
go mod init go-serpapi-demo
go get github.com/serpapi/google-search-results-golang
go get github.com/gin-gonic/gin
export SERPAPI_KEY=your_free_key_from_serpapi.com

#. Example 1: Google Jobs - The Code I Use


package main

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

func main() {
  params := map[string]string{
    "engine": "google_jobs",
    "q": "Go Developer",
    "location": "Remote",
    "hl": "en",
  }
  search := g.NewGoogleSearch(params, os.Getenv("SERPAPI_KEY"))
  results, err := search.GetJSON()
  if err!= nil { panic(err) }

  jobs := results["jobs_results"].([]interface{})
  for _, j := range jobs {
    job := j.(map[string]interface{})
    fmt.Printf("[%s] %s - %s\n", job["via"], job["title"], job["company_name"])
    // You can also get: job["extensions"], job["detected_extensions"]
  }
}

#. Example 2: Google Shopping Price Tracker


params := map[string]string{
  "engine": "google_shopping",
  "q": "golang book",
}
search := g.NewGoogleSearch(params, os.Getenv("SERPAPI_KEY"))
results, _ := search.GetJSON()



By:Pires Aurélio 
Contact: aureliopires186@gmail.com 
https://blogspotangola.blogspot.com/?m=1
https://www.linkedin.com/in/pires-aur%C3%A9lio-511330385

Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.