抱歉,我使用的是响应而不是正文,这是正确的方法:
var request = require('request');
var htmlparser = require('htmlparser2');
var select = require('soupselect').select
var url = '';
function httpsHandler(err, response, body) {
if(err){
console.error('to err is human')
process.exit(1);
}
var parser = new htmlparser.Parser(htmlHandler);
parser.parseComplete(body);
}
var htmlHandler = new htmlparser.DefaultHandler( (error, dom) => {
if (error){
console.log( 'error', error );
process.exit(1);
}
var options = extractData( dom );
});
function extractData( dom ){
var collection = select(dom, '#ctl00_LeftColumnMiddle_Table1 table td');
collection.forEach( ( licenses ) => {
licenses.children.forEach( ( license, i ) => {
var data = ( license.data ) ? license.data : license.children[0].data
console.log( data );
});
})
}
//entry point
request.get( url , httpsHandler );