olxvn

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package olxvn is the library behind the olxvn command line: the HTTP client, HTML scraping, and typed data models for OLX Vietnam (olx.vn), a top-10 classifieds platform in Vietnam.

Listing detail pages embed JSON-LD Product/Offer schema for core fields. Category listing pages use ?page=N pagination. Listing URLs follow the pattern: https://www.olx.vn/item/{slug}/.

Index

Constants

View Source
const DefaultUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"

DefaultUserAgent mimics a real browser.

View Source
const Host = "www.olx.vn"

Host is the canonical site hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client talks to the OLX Vietnam website over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client from DefaultConfig.

func NewClientWithConfig

func NewClientWithConfig(cfg Config) *Client

NewClientWithConfig returns a Client built from cfg.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

Get fetches rawURL and returns the body bytes, pacing and retrying on transient errors.

func (*Client) GetListing

func (c *Client) GetListing(ctx context.Context, slug string) (*Listing, error)

GetListing fetches a listing detail page by its slug.

func (*Client) ListListings

func (c *Client) ListListings(ctx context.Context, categorySlug string, page, limit int) ([]*Listing, error)

ListListings fetches listing links from a category page.

type Config

type Config struct {
	BaseURL   string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
	UserAgent string
}

Config holds the tunable knobs for the HTTP client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible production defaults.

type Domain

type Domain struct{}

Domain is the OLX Vietnam kit driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

func (Domain) Info

func (Domain) Info() kit.DomainInfo

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

func (Domain) Register

func (Domain) Register(app *kit.App)

type Listing

type Listing struct {
	// Slug is the item slug from the URL: the canonical ID.
	Slug            string  `json:"slug"                    kit:"id" table:"slug"`
	Title           string  `json:"title"                            table:"title"`
	URL             string  `json:"url,omitempty"                    table:"url,url"`
	Price           float64 `json:"price,omitempty"                  table:"price"`
	PriceNegotiable bool    `json:"price_negotiable,omitempty"       table:"negotiable"`
	Description     string  `json:"description,omitempty"            table:"-"`
	Category        string  `json:"category,omitempty"               table:"category"`
	City            string  `json:"city,omitempty"                   table:"city"`
	Condition       string  `json:"condition,omitempty"              table:"condition"`
	SellerName      string  `json:"seller_name,omitempty"            table:"seller"`
	PostedAt        string  `json:"posted_at,omitempty"              table:"posted_at"`
	FetchedAt       string  `json:"fetched_at,omitempty"             table:"fetched_at"`
}

Listing is one OLX Vietnam classified ad.

Jump to

Keyboard shortcuts

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