我需要从网址中过滤掉返回数据。这个数据是html,我只需要某些具有特定ID或类的div而不是所有内容。我正在使用节点模块"请求"向URL发出请求并尝试使用下划线模块过滤掉不需要的div或标签。我不确定我是否采取了正确的方法。这是我的代码。任何帮助将不胜感激。提前谢谢。
var request = require('request');
var _ = require('underscore');
module.exports = function(website, provinceName, cityName){
return new Promise(function (resolve, reject){
var encodedCity = encodeURIComponent(cityName);
var encodedProvince = encodeURIComponent(provinceName);
var url = website + provinceName + '/' + cityName;
// make a request to the url and get the data back
if(url){
request({
url: url
}, function(error, response, body){
if(error){
reject('Unable to fetch the lawyers' + error);
}else{
// filter out all the data that does not have class=classname or id=idName
var html = _.pick(body, '.classname', 'myidname');
//then loop over and only send back the ones with class=classname or id=idName
_.each(html, function(){
});
resolve(html);
}
});
}else{
reject();
}
});
};