package main
import (
"fmt"
"log"
"net/http"
"net/url"
"os"
)
func main() {
searchQuery := "your search query here"
searchURL := buildGoogleSearchURL(searchQuery)
response, err := http.Get(searchURL)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
if response.StatusCode != http.StatusOK {
fmt.Printf("Error: Unable to fetch search results. Status code: %d\n", response.StatusCode)
os.Exit(1)
}
fmt.Println("Google Search Results:")
fmt.Println("-----------------------")
// Process the response body as needed
// (e.g., parse and display search results)
fmt.Println("-----------------------")
}
func buildGoogleSearchURL(query string) string {
baseURL := "https://www.google.com/search"
searchParams := url.Values{}
searchParams.Add("q", query)
searchParams.Add("num", "10") // Number of search results to display (adjust as needed)
fullURL := fmt.Sprintf("%s?%s", baseURL, searchParams.Encode())
return fullURL
}