相关疑难解决方法(0)

如何控制PhantomJS跳过下载某种资源?

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)

phantomjs

52
推荐指数
3
解决办法
2万
查看次数

防止Python驱动的PhantomJS/Selenium中的CSS /其他资源下载

我试图通过阻止下载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)

via:如何控制PhantomJS跳过下载某种资源?

如何/在哪里可以在由Python驱动的Selenium中实现此代码?或者,还有另一种更好的方法来阻止CSS /其他资源下载吗?

注意:我已经找到了如何通过编辑service_args变量来阻止图像下载:

如何在python webdriver中为phantomjs/ghostdriver设置代理?

PhantomJS 1.8与python上的Selenium.如何阻止图像?

但是service_args无法帮助我使用像CSS这样的资源.谢谢!

python selenium web-scraping headless-browser phantomjs

14
推荐指数
1
解决办法
6583
查看次数