我试图弄清楚如何通过HTTP代理路由我的请求.
我正在初始化这样的webdriver:
user_agent = 'my user agent 1.0'
DesiredCapabilities.PHANTOMJS['phantomjs.page.settings.userAgent'] = user_agent
driver = webdriver.PhantomJS()
Run Code Online (Sandbox Code Playgroud)
我已经浏览了文档和源代码,似乎无法通过webdriver找到使用phantomjs代理服务器的方法.
有什么建议?
我试图通过阻止下载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这样的资源.谢谢!