I'm trying to speed up Selenium/PhantomJS webscraper in Python by preventing download of CSS/other resources. All I need to download is img src and alt tags. I've found this code:
page.onResourceRequested = function(requestData, request) {
if ((/http:\/\/.+?\.css/gi).test(requestData['url']) || requestData['Content-Type'] == 'text/css') {
console.log('The url of the request is matching. Aborting: ' + requestData['url']);
request.abort();
}
};
via: How can I control PhantomJS to skip download some kind of resource?
How/where can I implement this code in Selenium driven by Python? Or, is there another better way to stop CSS/other resources from downloading?
Note: I've already found how to prevent image download by editing service_args variable via:
How do I set a proxy for phantomjs/ghostdriver in python webdriver?
and
PhantomJS 1.8 with Selenium on python. How to block images?
But service_args can't help me with resources like CSS. Thanks!