baidu

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package baidu is the library behind the baidu command: the HTTP client, request shaping, and the typed data models for Baidu.

Two APIs used: top.baidu.com for hot search boards (no key required) and suggestion.baidu.com for query suggestions (JSONP, no key required).

Package baidu provides typed data models for the baidu command.

Index

Constants

View Source
const (

	// DefaultUserAgent identifies the client to Baidu APIs.
	DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Baidu hot search and suggest APIs.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client with the given config.

func (*Client) Hot

func (c *Client) Hot(ctx context.Context, tab string, limit int) ([]HotItem, error)

Hot fetches the hot search board for the given tab and returns up to limit items. tab is one of: realtime, novel, movie, teleplay, car.

func (*Client) Suggest

func (c *Client) Suggest(ctx context.Context, query string) ([]Suggestion, error)

Suggest fetches query suggestions for the given search term. Returns up to 10 items from the Baidu suggest JSONP API.

type Config

type Config struct {
	BaseURL        string
	SuggestBaseURL string
	UserAgent      string
	Rate           time.Duration
	Timeout        time.Duration
	Retries        int
}

Config holds constructor parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type HotItem

type HotItem struct {
	Rank int    `json:"rank"`
	Word string `json:"word"`
	Tag  string `json:"tag"`
	URL  string `json:"url"`
}

HotItem is one entry from the Baidu hot search board.

type Suggestion

type Suggestion struct {
	Rank int    `json:"rank"`
	Word string `json:"word"`
}

Suggestion is one entry from the Baidu suggest API.

Jump to

Keyboard shortcuts

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