【发布时间】:2021-06-08 20:05:46
【问题描述】:
我正在尝试将 scraper 与 nodejs 和cheerio 结合起来。 到目前为止我有这个:
class ScraperService {
static getDwelling(url) {
const dwelling = {
images: []
};
return new Promise((resolve, reject) => {
request(`https://www.zonaprop.com.ar/propiedades/${url}`, (err, resp, html) => {
if(err || resp.statusCode === 404) {
return reject(err);
}
const $ = cheerio.load(html);
pe = $('.price-operation', '#article-container').text();
dwelling.price = $('.price-items', '#article-container').text();
dwelling.description = $('.description-container', '#article-container').html();
//getting images here
$('#tab-foto-flickity').find('img').each(() => {dwelling.images.push(this);});
resolve(dwelling);
});
});
}
}
module.exports = ScraperService;
【问题讨论】: