baidu

package
v0.8.19 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Selectors = struct {
	Captcha       string
	Timeout       string
	NoResults     string
	Results       string
	ResultsAlt    []string
	AdMarkers     []string
	ImageJSONRoot []string
	Link          string
	Desc          string
	// DescAlt are additional description containers tried when Desc misses.
	// Baidu varies abstract markup across feature blocks (info cards, news rows).
	DescAlt []string
}{
	Captcha:       "div.passMod_dialog-wrapper",
	Timeout:       "button.timeout-button",
	NoResults:     "div.content_none, div.nors",
	Results:       "#content_left div.result.c-container",
	ResultsAlt:    []string{"#content_left div.result-op.c-container", "div.c-container.new-pmd"},
	AdMarkers:     []string{"[data-tuiguang]", "[data-click*='tuiguang']", ".ec-tuiguang", ".c-icon-bear-p"},
	ImageJSONRoot: []string{"body > pre", "pre"},
	Link:          "a",
	Desc:          "div.c-abstract",

	DescAlt: []string{"[class*='content-right_']", "[class*='summary-gap_']", "div.text_2NOr6"},
}

Selectors is the single source of truth for Baidu SERP CSS selectors.

Functions

func BuildImageURL added in v0.4.1

func BuildImageURL(q core.Query, pageNum int) (string, error)

BuildImageURL builds a Baidu image search URL from Query fields and page index. It returns an error when the query text is empty.

func BuildURL

func BuildURL(q core.Query) (string, error)

BuildURL builds a Baidu web search URL from Query fields. It returns an error when query text, date, or pagination parameters are invalid.

func ParseHTML added in v0.7.13

func ParseHTML(r io.Reader) ([]core.SearchResult, error)

ParseHTML parses a Baidu SERP HTML document and returns search results. No network I/O.

func Search(ctx context.Context, query core.Query) (results []core.SearchResult, err error)

Types

type Baidu

type Baidu struct {
	core.Browser
	core.SearchEngineOptions
	// contains filtered or unexported fields
}

Baidu implements core.SearchEngine for Baidu SERP pages.

func New

func New(browser core.Browser, opts core.SearchEngineOptions) *Baidu

New creates a Baidu engine instance with browser/runtime options applied.

func (*Baidu) Name

func (baid *Baidu) Name() string

Name returns the stable engine identifier.

func (*Baidu) Search

func (baid *Baidu) Search(ctx context.Context, query core.Query) (results []core.SearchResult, err error)

Search executes a Baidu web search and returns normalized search results. It may return core.ErrCaptcha or core.ErrSearchTimeout.

func (*Baidu) SearchImage added in v0.4.1

func (baid *Baidu) SearchImage(ctx context.Context, query core.Query) ([]core.SearchResult, error)

SearchImage executes a Baidu image search and returns normalized image results. It may return core.ErrCaptcha or core.ErrSearchTimeout.

Jump to

Keyboard shortcuts

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