Documentation
¶
Index ¶
- Variables
- func BuildImageURL(q core.Query, page int) (string, error)
- func BuildURL(q core.Query, page int) (string, error)
- func ParseHTML(r io.Reader) ([]core.SearchResult, error)
- func Search(ctx context.Context, query core.Query) (results []core.SearchResult, err error)
- type ImageData
- type ImageEntity
- type Yandex
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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.
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) 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
SearchImage executes a Yandex image search and returns normalized image results. It may return core.ErrCaptcha or core.ErrSearchTimeout.