tiktok

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

README

tiktok-gofun

Tiktok scrapper for go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRateLimited     = errors.New("tiktok: rate limited")
	ErrNotFound        = errors.New("tiktok: not found")
	ErrAuthRequired    = errors.New("tiktok: authentication required")
	ErrCaptcha         = errors.New("tiktok: captcha required")
	ErrSigningFailed   = errors.New("tiktok: url signing failed")
	ErrBrowserNotReady = errors.New("tiktok: browser not initialized")
	ErrInvalidResponse = errors.New("tiktok: invalid response")
)

Functions

This section is empty.

Types

type Author

type Author struct {
	ID             string
	Username       string
	Nickname       string // Display name (bot detection: random/empty patterns).
	FollowerCount  int
	FollowingCount int
	VideoCount     int
	HeartCount     int // Total likes received across all videos.
	DiggCount      int // Total likes given by the user.
	Verified       bool
	Bio            string
	AvatarURL      string
}

Author represents a TikTok user profile with their stats.

type Scraper

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

Scraper is the main TikTok scraper. It uses pure HTTP for user profiles (SSR parsing) and a headless browser only for signing search URLs.

func New

func New() *Scraper

New creates a Scraper with sensible defaults. The browser is not launched until InitBrowser or Login is called.

func (*Scraper) Close

func (s *Scraper) Close() error

Close releases all resources including the headless browser if running.

func (*Scraper) GetCookies

func (s *Scraper) GetCookies() []*http.Cookie

GetCookies returns the current session cookies for tiktok.com.

func (*Scraper) GetUser

func (s *Scraper) GetUser(ctx context.Context, username string) (Author, error)

GetUser fetches a TikTok user profile via SSR HTML parsing. This is pure HTTP — no browser or login required.

func (*Scraper) InitBrowser

func (s *Scraper) InitBrowser() error

InitBrowser launches a headless Chrome instance with stealth mode. The browser stays open in the background for URL signing only.

func (*Scraper) IsLoggedIn

func (s *Scraper) IsLoggedIn() bool

IsLoggedIn reports whether the scraper has an active session.

func (*Scraper) LoadCookies

func (s *Scraper) LoadCookies(path string) error

LoadCookies reads cookies from a JSON file and sets them on the client.

func (*Scraper) Login

func (s *Scraper) Login(username, password string) error

Login automates TikTok login via the headless browser. After login, cookies are synced to the HTTP client for subsequent API requests.

func (*Scraper) LoginWithCookies

func (s *Scraper) LoginWithCookies(path string) error

LoginWithCookies loads saved cookies and initializes the browser for signing.

func (*Scraper) SaveCookies

func (s *Scraper) SaveCookies(path string) error

SaveCookies writes session cookies to a JSON file.

func (*Scraper) SearchByHashtag

func (s *Scraper) SearchByHashtag(ctx context.Context, hashtag string, limit int) ([]Video, error)

SearchByHashtag searches TikTok for videos under a specific hashtag. Requires an initialized browser and authentication.

func (*Scraper) SearchVideos

func (s *Scraper) SearchVideos(ctx context.Context, keyword string, limit int) ([]Video, error)

SearchVideos searches TikTok for videos matching the keyword. Requires an initialized browser (InitBrowser) and authentication.

func (*Scraper) SetCookies

func (s *Scraper) SetCookies(cookies []*http.Cookie)

SetCookies sets session cookies and extracts the msToken.

func (*Scraper) SetDebug added in v0.3.0

func (s *Scraper) SetDebug(enabled bool) *Scraper

SetDebug enables performance timing output to stderr.

func (*Scraper) SetProxy

func (s *Scraper) SetProxy(proxyAddr string) error

SetProxy configures an HTTP/HTTPS or SOCKS5 proxy for the HTTP client. Connection pooling and keep-alive settings are preserved.

func (*Scraper) WithProfileDelay

func (s *Scraper) WithProfileDelay(d time.Duration) *Scraper

WithProfileDelay sets the minimum delay between user profile requests.

func (*Scraper) WithSearchDelay

func (s *Scraper) WithSearchDelay(d time.Duration) *Scraper

WithSearchDelay sets the minimum delay between search/hashtag API requests.

type Video

type Video struct {
	ID          string
	Description string
	AuthorID    string
	Username    string
	CreatedAt   time.Time
	Views       int
	Likes       int
	Comments    int
	Shares      int
}

Video represents a TikTok video with its engagement metrics.

Directories

Path Synopsis
cmd
tiktok command

Jump to

Keyboard shortcuts

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