OLX Parser — a small CLI application for parsing OLX ads, storing results in PostgreSQL, and managing search filters.
This repository contains a tool that:
- stores search filters (URL, keywords, location)
- parses up to 5 first pages of search results (sequentially, with small delays)
- stores found ads in Postgres, avoiding duplicates
Imagine I want to find an affordable used MacBook Pro, second generation with 16GB RAM in 14".
I search on OLX "MacBook 14 M2 Pro 16gb" and see 37 results, but the vast majority are M1 Pro, Air, etc.
If we add keywords M2 Pro,14 to the search, we can easily find what we're specifically looking for in all that noise.
In my example, there were only 3 such items.
Future plans
- Regular periodic updates (scheduler/cron) for automatic re-parsing of saved filters.
- In case of new results — send notifications to Telegram, email.
- Configure update frequency and notification channel through configuration.
- ✅ Parsing ads from OLX.ua
- ✅ Flexible filter system (keywords, location)
- ✅ Storing ads and filters in PostgreSQL
- ✅ CLI for managing filters and parsing
- ✅ Automatic duplicate avoidance
- ✅ Support for updating existing ads
- Added a background "watch" worker that periodically examines saved filters and parses only those that are due for refresh.
- New filter attributes stored in DB:
refresh_time(minutes) andrefreshed_at(timestamp). The schema is migrated on startup if needed. - The
--refresh-minutesparameter is now required when creating a filter; it controls how often the filter should be refreshed (in minutes). - New command:
watch— runs a continuous loop, checks filters that are due (based onrefreshed_at + refresh_time), parses them, saves new ads and appends entries for new ads into a log file (JSONL). Use--log-fileto change the log path. - The watcher updates
refreshed_atafter a successful check for a filter.
Operational notes:
- The watcher wakes periodically (default polling tick is 30s) and only parses filters that are due; this means the program does a light check every tick and executes parsing only when necessary.
- To avoid overlapping work and reduce load on OLX, the implementation is sequential by default; consider enabling a controlled worker pool or advisory locking for multi-instance deployments.
- Logs for new ads are appended to the configured file; consider setting up log rotation for long-running usage.
See the "Usage" section below for examples how to run the watcher.
Requirements:
- Go 1.23 or newer
- PostgreSQL 12 or newer
- Internet access for parsing
Installation:
# Clone the repository
cd /path/to/olx
# Install dependencies and build the app
go mod download
go build -o olx-parser .Database configuration:
Default parameters: localhost:5432, user/password/db: olx.
Change via environment variables:
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=olx
export DB_PASSWORD=olx
export DB_NAME=olxThe program automatically creates required tables on startup.
Basic example:
./olx-parser add-filter \
--url "https://www.olx.ua/uk/kiev/q-MacBook-14-M2-Pro-16gb/?search%5Bfilter_float_price:from%5D=30000&search%5Bfilter_float_price:to%5D=50000" \
--keywords "M2 Pro,14" \
--location "Kyiv" \
--refresh-minutes 30Parameters:
--url— URL of OLX search page (required)--keywords— keywords separated by comma (optional)--location— location for additional filtering (optional)--refresh-minutes— how often to refresh this filter in minutes (required)
How parsing works:
The parser sequentially processes the first 5 pages of OLX results. Try to narrow down your search results as much as possible, leaving selective verification to the program.
If the location parameter is specified, parsing stops at the first ad from a different location — this ensures that OLX won't offer similar ads from other regions.
After collecting ads, a final check is applied: if keywords were specified when creating the filter, all of them must be present in the ad title. Only those ads that pass the check are saved to the database.
Usage examples:
# Example 1: Without location in URL and without keywords (simplest search)
./olx-parser add-filter \
--url "https://www.olx.ua/uk/elektronika/telefony-i-aksesuary/q-iphone/"
# Example 2: With location in URL (must also specify in --location)
./olx-parser add-filter \
--url "https://www.olx.ua/uk/elektronika/telefony-i-aksesuary/kiev/q-iphone/" \
--location "Kyiv"
# Example 3: With keywords but without location (filtering only by words)
./olx-parser add-filter \
--url "https://www.olx.ua/uk/list/q-iPhone-15-Pro-Max/" \
--keywords "15,Pro Max"
# Example 4: With location and keywords (most precise search)
./olx-parser add-filter \
--url "https://www.olx.ua/uk/kiev/q-iPhone-15-Pro-Max/" \
--keywords "15,Pro Max" \
--location "Kyiv"
# Example 5: Macbook with price range, location and keywords
./olx-parser add-filter \
--name "Macbook 14 M2 Pro 16gb" \
--url "https://www.olx.ua/uk/kiev/q-MacBook-14-M2-Pro-16gb/?search%5Bfilter_float_price:from%5D=30000&search%5Bfilter_float_price:to%5D=50000" \
--keywords "M2 Pro,14,16" \
--location "Kyiv"
--refresh-minutes 30./olx-parser list-filters./olx-parser parse 1# By filter name (last 50)
./olx-parser show-ads "Macbook 14 M2 Pro 16gb"
# By filter ID with limit
./olx-parser show-ads 1 --limit 10
# Output in JSON format
./olx-parser show-ads 1 --jsonParameters:
--limit- maximum number of results (default: 50)--json- output result in JSON format
# Deletes the filter and all associated ads
./olx-parser delete-filter 1MIT