我有一个返回对象数组的函数:
() => Array.from(document.querySelectorAll("table.inzeraty"))
.map(offer => {
const image = offer.querySelector('img.obrazek')
const desc = offer.querySelector('div.popis')
const location = offer.querySelector('tbody:nth-child(1) td:nth-child(3)')
return ({
title: offer.querySelector('span.nadpis > a').innerText.trim(),
price: offer.querySelector('span.cena > b').innerText.trim(),
image: image ? image.src : '',
desc: desc ? desc.innerText.trim() : '',
location: location ? location.innerText.trim() : '',
link: offer.querySelector('span.nadpis > a').href
})
})
该函数返回如下所示的Array:
[ { title: 'Kentoya Viking 125',
price: '22 000 Kč',
image: 'https://www.bazos.cz/img/1t/363/94935363.jpg',
desc: 'Prodám skútr Kentoya.',
location: 'Karlovy Vary\n360 01',
link: 'https://motorky.bazos.cz/inzerat/94935363/Kentoya-Viking-125.php' },
{ title: 'KYMCO MOVIE XL 150',
price: '15 000 Kč',
image: 'https://www.bazos.cz/img/1t/377/94934377.jpg?t=1538135827',
desc: 'Rv.2002. najeto.16800km.',
location: 'Praha 1\n110 00',
link: 'https://motorky.bazos.cz/inzerat/94934377/KYMCO-MOVIE-XL-150.php' } ]
我想知道我是否能够将结果转换为json文件,然后将其保存到firebase数据库中。
谢谢。