jQueryを使用してNode.jsで小さなアプリケーションを構築しようとしています。これは、提供された場所でコンテンツを要求します。URL が HTML 以外のリソースを指している場合、返されたコンテンツ タイプが出力されます。それ以外の場合は、HTML データを読み取り、ページのタイトルと説明を出力し、その後にページ上のクリック可能なリンクのリストを出力します。これが私のコードです:
var request             = require('request'),    
    jsdom               = require('jsdom'),
    fs                  = require('fs'),
    colors              = require('colors'),
    argv                = require('optimist').argv;
    
    colors.setTheme({ c1: 'blue', c2: 'red', c3: 'inverse' });
var myFunc = function( link, cb ){
console.log( 'requesting page: '.c3 + link.c3 );
// Step 1 - request to the page
request({
        uri: link,
    }, function (err, response, body) {
    
        // Handle response issues
        if ( err || response.statusCode !== 200 ) {
            if ( !response ){
                console.log( 'Ooops! page doesn`t exist or wrong URL format'.c2 )
            } else {
                console.log('error: '+ response.statusCode )
            }
            cb();
        } else {
            console.log( 'response code: ' + response.statusCode )
            
            // Step 2 - invoking jsdom and jQuery
            jsdom.env({
                html: body,
                src: [
                    fs.readFileSync(__dirname + "/lib/jquery-1.9.1.min.js").toString()
                ],
                done: function(err, window) {
                    
                    if(err) {
                        cb();
                    } else {
                        var $ = window.$;
                        // Step 3, final part - parse content with jQuery selectors
                        console.log( '\nThis page is:\n'.c1 + $(body)[0]._ownerDocument._contentType )
                        console.log( '\nPage title: \n'.c1 + $('title').text().trim() );
                        console.log( $('head meta[name="description"]').attr('content') !== undefined ? '\nPage description: \n'.c1 + $('head meta[name="description"]').attr('content') + '\n' : '\nPage description: \n'.c1 + 'No description on the page\n'.c2);
                        console.log( '\nClickable links on the page: \n'.c1 )
                        $('a').each(function(){
                            if ( $(this).attr('href') !== undefined ){
                                console.log( $(this).attr('href').slice(0, 4) == 'http' ? $(this).attr('href') : link + $(this).attr('href'))
                            } 
                        });
                        cb();
                    }
                } 
            })
        }
    }
);
};
したがって、HTMLページを完全にスクレイピングしますが、この部分を実装する方法がわかりません
URL が HTML 以外のリソースを指している場合、返されたコンテンツ タイプが出力されます。
この部分を行う方法のアイデアを共有してください。前もって感謝します!