googlesearch

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("google block")

ErrBlocked indicates that Google has detected that you were scraping and temporarily blocked you. The duration of the block is unspecified.

See: https://github.com/rocketlaunchr/google-search#warning-warning

View Source
var GoogleDomains = map[string]string{}/* 198 elements not displayed */

GoogleDomains represents localized Google homepages. The 2 letter country code is based on ISO 3166-1 alpha-2.

See: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2

View Source
var RateLimit = rate.NewLimiter(rate.Inf, 0)

RateLimit sets a global limit to how many requests to Google Search can be made in a given time interval. The default is unlimited (but obviously Google Search will block you temporarily if you do too many calls too quickly).

See: https://godoc.org/golang.org/x/time/rate#NewLimiter

Functions

This section is empty.

Types

type Result

type Result struct {

	// Rank is the order number of the search result.
	Rank int `json:"rank"`

	// URL of result.
	URL string `json:"url"`

	// Title of result.
	Title string `json:"title"`

	// Description of the result.
	Description string `json:"description"`
}

Result represents a single result from Google Search.

func Search(ctx context.Context, searchTerm string, opts ...SearchOptions) ([]Result, error)

Search returns a list of search results from Google.

type SearchOptions

type SearchOptions struct {

	// CountryCode sets the ISO 3166-1 alpha-2 code of the localized Google Search homepage to use.
	// The default is "us", which will return results from https://www.google.com.
	CountryCode string

	// LanguageCode sets the language code.
	// Default: en
	LanguageCode string

	// Limit sets how many results to fetch (at maximum).
	Limit int

	// Start sets from what rank the new result set should return.
	Start int

	// UserAgent sets the UserAgent of the http request.
	// Default: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
	UserAgent string

	// OverLimit searches for more results than that specified by Limit.
	// It then reduces the returned results to match Limit.
	OverLimit bool

	// ProxyAddr sets a proxy address to avoid IP blocking.
	ProxyAddr string

	// FollowNextPage, when set, scrapes subsequent result pages.
	FollowNextPage bool
}

SearchOptions modifies how the Search function behaves.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL