How can I control PhantomJS to skip download some kind of resource?

后端 未结 4 2110
Happy的楠姐
Happy的楠姐 2020-12-13 03:59

phantomjs has config loadImage,

but I want more,

how can I control phantomjs to skip download some kind of resource,

such as css etc...

===

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 04:19

    Use page.onResourceRequested, as in example loadurlwithoutcss.js:

    page.onResourceRequested = function(requestData, request) {
        if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || 
                requestData.headers['Content-Type'] == 'text/css') {
            console.log('The url of the request is matching. Aborting: ' + requestData['url']);
            request.abort();
        }
    };
    

提交回复
热议问题