douban

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 douban is the library behind the douban command: the HTTP client, request shaping, and typed data models for Douban (豆瓣).

The client fetches Douban subject-search pages over HTTPS and extracts structured results from the embedded window.__DATA__ JSON. No API key or authentication is required. It sets a real User-Agent, paces requests, and retries transient 429/5xx errors with exponential backoff.

Index

Constants

View Source
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"

DefaultUserAgent is the browser-like User-Agent sent with every request.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to Douban's search pages.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query, searchType string, limit int) ([]Result, error)

Search fetches Douban search results for query and searchType. searchType must be one of "book", "movie", or "music". Up to limit results are returned; pass 0 to use a reasonable default (15).

type Config

type Config struct {
	BaseURL   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 Result

type Result struct {
	Rank     int    `json:"rank"`
	Title    string `json:"title"`
	Rating   string `json:"rating"`
	Abstract string `json:"abstract"`
	URL      string `json:"url"`
}

Result is the record emitted for every matched search result.

Jump to

Keyboard shortcuts

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