I want to search a Word and the Link. If it found, then I want to return the link. Everything works fine if I output it to console.log
. If I make an object, and add the Link to the object and if I return it, then I get undefined
. Why? Cheerio
found my word successfully (I tested with console.log
)
I want to add the found links into an object. But it doesn't work
'use strict';
const superagent = require('superagent');
const cheerio = require('cheerio');
const email = domain => {
const email_obj = {
email_exists: false,
email_link: false
};
superagent
.get(domain)
.end((err, res) => {
let $ = cheerio.load(res.text);
let links = $('a');
$(links).map((i, link) => {
const data = $(link).text().toLocaleLowerCase().trim();
if (data.includes('e-mail') && $(link).attr('href') != '' && $(link).attr('href') != null) {
email_obj.imprint_exists = true;
email_obj.imprint_link = $(link).attr('href');
console.log($(link).attr('href'));
}
});
});
return email_obj;
}
module.exports = email;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…