Export OLX listing titles and prices to a CSV file directly from the listing page
// ==UserScript==
// @name OLX Listing Scraper (CSV Export)
// @namespace krymzone.olx-listing-scraper
// @version 1.0.0
// @description Export OLX listing titles and prices to a CSV file directly from the listing page
// @author krymzone
// @match https://www.olx.ro/*
// @grant none
// @license MIT
// ==/UserScript==
/*
MIT License
Copyright (c) 2026 YourName
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
(function() {
'use strict';
// Utility to convert array of objects to CSV
function exportToCSV(data, filename = 'olx_data.csv') {
const csvRows = [];
const headers = Object.keys(data[0]);
csvRows.push(headers.join(','));
for (const row of data) {
const values = headers.map(h => `"${row[h]}"`);
csvRows.push(values.join(','));
}
const csvContent = csvRows.join('\n');
const blob = new Blob([csvContent], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
// Scrape listings
function scrapeListings() {
const listings = document.querySelectorAll('[data-testid="l-card"]');
const data = [];
listings.forEach(listing => {
const titleEl = listing.querySelector('[data-testid="ad-card-title"] h4');
const priceEl = listing.querySelector('[data-testid="ad-price"]');
if (titleEl && priceEl) {
data.push({
title: titleEl.innerText.trim(),
price: priceEl.innerText.trim()
});
}
});
if (data.length > 0) {
exportToCSV(data);
} else {
alert('No listings found!');
}
}
const btn = document.createElement('button');
btn.textContent = 'Scrape OLX Listings';
btn.style.position = 'fixed';
btn.style.bottom = '10px';
btn.style.right = '10px';
btn.style.zIndex = 1000;
btn.style.padding = '10px';
btn.style.backgroundColor = '#4CAF50';
btn.style.color = 'white';
btn.style.border = 'none';
btn.style.cursor = 'pointer';
btn.onclick = scrapeListings;
document.body.appendChild(btn);
})();