phantomjs有配置loadImage,
但我想要更多,
如何控制phantomjs跳过下载某种资源,
比如css等......
=====
好消息:此功能已添加.
https://code.google.com/p/phantomjs/issues/detail?id=230
要旨:
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();
}
};
Run Code Online (Sandbox Code Playgroud) 我试图通过阻止下载CSS /其他资源来加速Python中的Selenium/PhantomJS webscraper.我需要下载的是img src和alt标签.我发现了这段代码:
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();
}
};
Run Code Online (Sandbox Code Playgroud)
如何/在哪里可以在由Python驱动的Selenium中实现此代码?或者,还有另一种更好的方法来阻止CSS /其他资源下载吗?
注意:我已经找到了如何通过编辑service_args变量来阻止图像下载:
如何在python webdriver中为phantomjs/ghostdriver设置代理?
和
PhantomJS 1.8与python上的Selenium.如何阻止图像?
但是service_args无法帮助我使用像CSS这样的资源.谢谢!