yandex

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Selectors = struct {
	Captcha   string
	NoResults string
	Results   string
	AdMarkers []string
	// LinkPrimary is preferred over a generic <a>; falls back to title.Closest("a")
	// then the first <a> in the result block when absent.
	LinkPrimary   string
	Link          string
	Title         string
	Desc          string
	DescFallback  string
	ImageItems    string
	ImageItemsAlt []string
	ImageStateAll string
}{
	Captcha:   "div.CheckboxCaptcha",
	NoResults: "div.EmptySearchResults",
	Results:   "li[data-fast], li.serp-item",
	AdMarkers: []string{
		"[data-fast-name='direct']",
		"[data-fast-name='serp-adv']",
		"[data-bem*='serp-adv']",
		".serp-adv-item",
		".serp-adv__found",
		"[aria-label='Реклама']",
		"[title='Реклама']",
	},
	LinkPrimary:   "a.OrganicTitle-Link",
	Link:          "a",
	Title:         "h2",
	Desc:          "span.OrganicTextContentSpan",
	DescFallback:  "div.OrganicText",
	ImageItems:    "div[role='main'] div[data-state]",
	ImageItemsAlt: []string{"div[data-state*='serpList']"},
	ImageStateAll: "div[data-state]",
}

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

Functions

func BuildImageURL added in v0.4.1

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

BuildImageURL builds a Yandex image search URL for the provided query and page index. It returns an error when the resulting query text is empty.

func BuildURL

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

BuildURL builds a Yandex web search URL for the provided query and page index. It returns an error when the resulting query text is empty.

func ParseHTML added in v0.7.13

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

ParseHTML parses a Yandex 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 ImageData added in v0.4.1

type ImageData struct {
	InitalState struct {
		SerpList struct {
			Items struct {
				Entities map[string]ImageEntity `json:"entities"`
			} `json:"items"`
		} `json:"serpList"`
	} `json:"initialState"`
}

ImageData maps the subset of Yandex JSON state used by parser code.

type ImageEntity added in v0.4.1

type ImageEntity struct {
	ID        string `json:"id"`
	Rank      int    `json:"pos"`
	Width     int    `json:"origWidth"`
	Height    int    `json:"origHeight"`
	Title     string `json:"alt"`
	OrigURL   string `json:"origUrl"`
	ThumbURL  string `json:"image"`
	Freshness string `json:"freshnessCounter"`
	IsGIF     bool   `json:"gifLabel"`
}

ImageEntity contains one image record from Yandex image search state JSON.

type Yandex

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

Yandex implements core.SearchEngine for Yandex SERP pages.

func New

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

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

func (*Yandex) Name

func (yand *Yandex) Name() string

Name returns the stable engine identifier.

func (*Yandex) Search

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

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

func (*Yandex) SearchImage added in v0.4.1

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

SearchImage executes a Yandex 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