Documentation
¶
Index ¶
- Variables
- type Author
- type Scraper
- func (s *Scraper) Close() error
- func (s *Scraper) GetCookies() []*http.Cookie
- func (s *Scraper) GetUser(ctx context.Context, username string) (Author, error)
- func (s *Scraper) InitBrowser() error
- func (s *Scraper) IsLoggedIn() bool
- func (s *Scraper) LoadCookies(path string) error
- func (s *Scraper) Login(username, password string) error
- func (s *Scraper) LoginWithCookies(path string) error
- func (s *Scraper) SaveCookies(path string) error
- func (s *Scraper) SearchByHashtag(ctx context.Context, hashtag string, limit int) ([]Video, error)
- func (s *Scraper) SearchVideos(ctx context.Context, keyword string, limit int) ([]Video, error)
- func (s *Scraper) SetCookies(cookies []*http.Cookie)
- func (s *Scraper) SetDebug(enabled bool) *Scraper
- func (s *Scraper) SetProxy(proxyAddr string) error
- func (s *Scraper) WithProfileDelay(d time.Duration) *Scraper
- func (s *Scraper) WithSearchDelay(d time.Duration) *Scraper
- type Video
Constants ¶
This section is empty.
Variables ¶
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) GetCookies ¶
GetCookies returns the current session cookies for tiktok.com.
func (*Scraper) GetUser ¶
GetUser fetches a TikTok user profile via SSR HTML parsing. This is pure HTTP — no browser or login required.
func (*Scraper) InitBrowser ¶
InitBrowser launches a headless Chrome instance with stealth mode. The browser stays open in the background for URL signing only.
func (*Scraper) IsLoggedIn ¶
IsLoggedIn reports whether the scraper has an active session.
func (*Scraper) LoadCookies ¶
LoadCookies reads cookies from a JSON file and sets them on the client.
func (*Scraper) Login ¶
Login automates TikTok login via the headless browser. After login, cookies are synced to the HTTP client for subsequent API requests.
func (*Scraper) LoginWithCookies ¶
LoginWithCookies loads saved cookies and initializes the browser for signing.
func (*Scraper) SaveCookies ¶
SaveCookies writes session cookies to a JSON file.
func (*Scraper) SearchByHashtag ¶
SearchByHashtag searches TikTok for videos under a specific hashtag. Requires an initialized browser and authentication.
func (*Scraper) SearchVideos ¶
SearchVideos searches TikTok for videos matching the keyword. Requires an initialized browser (InitBrowser) and authentication.
func (*Scraper) SetCookies ¶
SetCookies sets session cookies and extracts the msToken.
func (*Scraper) SetProxy ¶
SetProxy configures an HTTP/HTTPS or SOCKS5 proxy for the HTTP client. Connection pooling and keep-alive settings are preserved.
func (*Scraper) WithProfileDelay ¶
WithProfileDelay sets the minimum delay between user profile requests.