parser

package module
v0.0.0-...-b73ae04 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 10 Imported by: 0

README

tbank-pulse-auto

tbank-pulse parser for w_popularity.

Scrapes public Tinkoff Investments "Pulse" profile pages on tbank.ru.

Strategy

  • Primary: HTTP GET of https://www.tbank.ru/invest/social/profile/<handle>/?author=profile with a desktop browser User-Agent. We scan every <script type="application/json"> tag in the response and walk the parsed payloads for the deepest object containing follower-like (followers, subscribersCount, followersCount, …) and post-like (posts, postsCount, publicationsCount, …) fields.

    In practice T-Bank does not use Next.js but its own "tramvai" framework, so the data lives at __TRAMVAI_CHILD_STATE__ -> social-profile@<hash>.stores.investSocialProfiles.<handle> rather than __NEXT_DATA__. The walker handles both shapes.

  • Fallback (TODO): camoufox browser automation, driven by Config.CamoufoxURL. Not wired yet — needed because the Pulse post feed itself is currently fetched client-side via authenticated XHRs after hydration, so a bare HTTP scrape can only recover profile-level counters, not per-post engagement. A 403 from the edge also flips the parser into the "switch to camoufox" hint.

Error mapping
Upstream Sentinel
HTTP 403 shared.ErrAuth
HTTP 404 shared.ErrNotFound
HTTP 429 shared.ErrRateLimited
HTTP 5xx / I/O shared.ErrTransient
Missing NEXT_DATA or no profile object shared.ErrNotFound

Usage

import parser "github.com/suenot/tbank-pulse-auto"

p := parser.New(parser.Config{})
snap, err := p.FetchChannel(ctx, "profit_maker")
if err != nil { /* ... */ }

posts, err := p.FetchRecentPosts(ctx, "profit_maker", time.Now().AddDate(0, 0, -7))
Config
Field Purpose
UserAgent Overrides outgoing UA. Defaults to a modern Chrome desktop string.
HTTPClient Custom client (e.g. tests).
HTTPTimeout Per-request timeout. Default 20s.
BaseURL Override the production host (for tests).
CamoufoxURL Reserved for the upcoming camoufox fallback.

License

MIT

Documentation

Overview

Package parser implements the w_popularity tbank-pulse adapter.

T-Bank Pulse (Тинькофф Инвестиции "Пульс") is a social feed for retail investors on tbank.ru. There is no documented public API for the social feed, but the SSR-rendered profile page embeds JSON payloads in <script type="application/json"> tags. We fetch the page HTML and walk those payloads to extract follower counts, post counts and the recent feed.

Strategy:

primary:  HTTP GET of https://www.tbank.ru/invest/social/profile/<handle>/
          and parse embedded JSON. Two known shapes:
            1. Next.js classic — <script id="__NEXT_DATA__"> with full
               page props.
            2. T-Bank "tramvai" framework — <script id="__TRAMVAI_CHILD_STATE__">
               where the profile lives at
               .social-profile@<hash>.stores.investSocialProfiles.<handle>.
          We scan all <script type="application/json"> tags and pick the
          deepest object containing follower-like + post-like fields.
fallback: camoufox (browser automation). TODO: not wired yet — see
          Config.CamoufoxURL. The post feed appears to be loaded client-side
          via authenticated XHRs, so getting post-level engagement on
          production likely requires camoufox.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// UserAgent overrides the outgoing User-Agent header.
	UserAgent string
	// HTTPClient lets tests inject a custom transport. When nil a default
	// client with HTTPTimeout is used.
	HTTPClient *http.Client
	// HTTPTimeout caps every outbound call. Default 20s.
	HTTPTimeout time.Duration
	// BaseURL overrides the production tbank.ru host. Tests use this to point
	// at an httptest.Server. Trailing slash is stripped.
	BaseURL string
	// CamoufoxURL, when set, will be used to drive a remote camoufox browser
	// for scraping. NOT wired in this revision — see package docs.
	CamoufoxURL string
}

Config controls runtime behaviour.

type TBankPulseParser

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

func New

func New(cfg Config) *TBankPulseParser

New constructs a TBankPulseParser ready for use.

func (*TBankPulseParser) FetchChannel

func (p *TBankPulseParser) FetchChannel(ctx context.Context, handle string) (shared.ChannelSnapshot, error)

FetchChannel returns one snapshot for the Pulse profile identified by handle.

func (*TBankPulseParser) FetchRecentPosts

func (p *TBankPulseParser) FetchRecentPosts(ctx context.Context, handle string, since time.Time) ([]shared.PostSnapshot, error)

FetchRecentPosts returns posts in the profile's recent feed whose published time is at or after `since`. Newest-first.

func (*TBankPulseParser) Platform

func (p *TBankPulseParser) Platform() shared.Platform

Jump to

Keyboard shortcuts

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