I have the following code
const link =
"https://www.daft.ie/property-for-rent/ireland?location=dublin&location=dublin-city&sort=publishDateDesc";
async function getLinks(url) {
return fetch(url)
.then((res) => res.text())
.then((html) => {
const $ = cheerio.load(html);
const sel = '[data-testid="results"] a[href]';
var links = [...$(sel)].map((e) => e.attribs.href);
return Promise.all(links);
});
}
getLinks(link).then(function(links) {
console.log(links);
});
This returns me an object array like this
[
'/for-rent/apartment-105-cabra-road-phibsborough-dublin-7/4071977',
'/for-rent/apartment-weavers-hall-leopardstown-dublin-18/4073220',
]
I would like this to be returned as array of strings so I can perform comparison operations more easily and so I can store the array in a variable.
Also I want know how to use await in this
I want it to work like this but it fails currently
const a = await getLinks(link1);
const b = await getLinks(link2);
where a and b contain string arrays.
How can I do this?