Untitled
unknown
plain_text
3 years ago
1.7 kB
8
Indexable
const axios = require('axios');
const cheerio = require('cheerio');
const url = 'https://www.propertyguru.com.sg/agent/natalie-cheng-349325?market=residential&listing_type=rent#agent-listings';
const getSalesPropertyListings = async (req, res) => {
try {
const options = {
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36',
},
proxy: {
host: 'your-proxy-host',
port: 'your-proxy-port',
auth: {
username: 'your-proxy-username',
password: 'your-proxy-password',
},
},
};
const response = await axios.get(url, options);
const html = response.data;
const $ = cheerio.load(html);
const activeListings = [];
$('.listing-card').each((index, element) => {
const listing = {};
listing.title = $(element).find('.listing-description-title').text().trim();
listing.address = $(element).find('.listing-description-address').text().trim();
listing.price = $(element).find('.price').text().trim();
listing.bedrooms = $(element).find('.bedroom').text().trim();
listing.bathrooms = $(element).find('.bathroom').text().trim();
activeListings.push(listing);
});
const output = activeListings.map(listing => {
return `Title: ${listing.title}\nAddress: ${listing.address}\nPrice: ${listing.price}\nBedrooms: ${listing.bedrooms}\nBathrooms: ${listing.bathrooms}\n`;
}).join('\n');
res.send(output);
} catch (error) {
console.log(error);
}
};
module.exports = {
getSalesPropertyListings,
};Editor is loading...