[英]Zombie.js - Downloading files support
I'm trying to handle download prompts in Zombie.js, looking through the API I don't see anything indicating how to do so. 我正在尝试处理Zombie.js中的下载提示,查看API我没有看到任何指示如何操作的内容。
Basically what I'm trying to do is navigate through an authentication required website, then click a button on the site (no href) that then automatically engages a download. 基本上我要做的是浏览一个身份验证所需的网站,然后点击网站上的按钮(无href),然后自动进行下载。 The downloaded file will then be renamed and sent to a specified folder.
然后,将重命名下载的文件并将其发送到指定的文件夹。
Is there a way to achieve this? 有没有办法实现这个目标?
Zombie.js doesn't seem to provide a method to directly do what you want, but internally it uses request to download files, then emits a response
event which you can listen for (see resources.coffee ): Zombie.js似乎没有提供直接执行您想要的方法,但在内部它使用请求下载文件,然后发出一个您可以监听的
response
事件(请参阅resources.coffee ):
var browser = new Zombie();
browser.on('response', function(request, response) {
browser.response = response;
});
browser.visit('http://test.com/', function() {
browser.clickLink('Download the file', function() {
// the 'response' handler should have run by now
var fileContents = browser.response.body;
});
});
This seems to work pretty well for me. 这对我来说似乎很有效。
possibly try: 可能会尝试:
http://phantomjs.org http://phantomjs.org
you should be able to manipulate the dom...to download. 你应该能够操纵dom ...下载。
https://github.com/ariya/phantomjs/wiki/Page-Automation https://github.com/ariya/phantomjs/wiki/Page-Automation
might have to write a separate script to do the file renaming. 可能必须编写一个单独的脚本来进行文件重命名。
As far as I know, and from taking a detailed look at the API of Zombie.js, I'd say no, this is not possible . 据我所知,并且从详细了解Zombie.js的API,我会说不,这是不可能的 。
I know it's not the answer you hoped for, but truth is not always nice. 我知道这不是你所希望的答案,但真相并不总是很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.