0
我想使網絡爬蟲從任何給定的網址提取標題,描述,關鍵字和圖像..提取後,我想保存在數據庫中...我的代碼不起作用圖片...任何幫助將不勝感激使網絡爬蟲想要提取的url中的圖像
var $ = cheerio.load(html);
var title = $('head title').text();
var keywords = $('head meta[name=keywords]').attr('content');
var desc = $('head meta[name=description]').attr('content');
var links = $('a');
var img= $('img').attr('content')
console.log('Crawling "%s" | %s',title,this.url);
async.map(links.map(function(){
var href = $(this).attr('href');
if(href && href != self._url && !(/^#(\w)+/.test(href)) && !util.imageRegexp.test(href)){
if(util.isExternal(href)){
return 'INSERT INTO `queue` SET `id` = \''+util.id()+'\', `url` = '+self.conn.escape(href)+', `from` = '+self.conn.escape(from);
console.log("self.conn.escape" + self.conn.escape)
}
else {
return 'INSERT INTO `queue` SET `id` = \''+util.id()+'\', `url` = '+self.conn.escape(util.resolveRelativeURL(href,self._url))+', `from` = '+self.conn.escape(from);
}
}
return false;
}).filter(function(el){
return !!el;
})
,this.conn.query.bind(this.conn),function(e,result){
if(e){
console.log('Error writing queue.');
console.log(e);
}
});
this.conn.query('INSERT INTO `websites` SET ?',{
id:util.id(),
url:this.url,
from:from,
title:title,
keywords:keywords || '',
img:img || '',
desc:desc || ''
}