Skip to content

Instantly share code, notes, and snippets.

@alex4o
Created February 20, 2023 16:32
Show Gist options
  • Save alex4o/78667400a89c9599a69995a4d721f2a2 to your computer and use it in GitHub Desktop.
Save alex4o/78667400a89c9599a69995a4d721f2a2 to your computer and use it in GitHub Desktop.
import axios from 'axios'
import { writeFileSync } from 'fs';
import { Parser } from 'json2csv'
import _ from "lodash"
let exampleDoc = {
REG_ID: '12427',
SHOPNAME: '-',
OWNER_INFO: 'Наименование: БУУСТ КОМПЮТЪРС<br/>ЕИК: 203316062',
DOMAIN: '-',
PLATFORM_DOMAIN: 'olx.bg',
GOODS: 'Други',
OWNER: 'БУУСТ КОМПЮТЪРС',
OWNER_PID: '203316062',
ACTIVE_TO: '19.02.2021',
REGDATE: '19.02.2021 16:15:52',
TERMDATE: null,
STATUS: '4',
MEDIATORS: null,
ISTPACTIVE: '1'
}
const fields = Object.keys(exampleDoc)
const count = 50;
let all = 100;
const results = []
let goodstype = "%D0%9A%D0%BE%D0%BC%D0%BF%D1%8E%D1%82%D1%80%D0%B8%20%D0%B8%20%D0%BF%D0%B5%D1%80%D0%B8%D1%84%D0%B5%D1%80%D0%B8%D1%8F"
for (let startIndex = 0; startIndex < all; startIndex += count) {
console.log(startIndex);
const data = await axios.get(`https://portal.nra.bg/pls/pub/!dec2009.REGREPESHOP.ajaxListDocuments?start=${startIndex}&length=${count}&goodsident=&goodstype=${goodstype}&ownerident=&ownername=&platformwebaddr=&shopname=&shopwebaddr=&status=`, {
headers: {
'Host': 'portal.nra.bg',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/109.0',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'X-Requested-With': 'XMLHttpRequest',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Cookie': 'TS0172b3d5=012f3188215686bb6aed7d259c54a00c3280abba15a217d93c74ccc27d78ff52f775edad41e97cb8ae25f9d25c29b5c7fa2b62c3e33a9fc2c8e626fc6064c2424e3c859c3a; TS0bb61346027=088a80bde8ab2000b1205dd25654fb41c03186f97c30450737c4c90272df7064cbc46b4f6a59919908e3e61cfe113000facd7a1501eb8dd6b84af698ef66c121db481c6d828fc91cd32bbb640c2142ae983c6449b3d42286e156a28d31326773; nra=!I9pMch41cHOP7Qp2DgFL64AVjcwD4PPZMO+ojJnqdZEIuKMiTG1ruCvmowGoBqf5EgUHnGOO7bNNpg=='
}
})
results.push(data.data.data)
all = data.data.recordsFiltered
}
const parser = new Parser({ fields });
const csv = parser.parse(_.flatten(results));
writeFileSync('./result1.csv', csv);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment