如何使用Zombie.js下载带有使用http-equiv元标记模拟Refresh HTTP标头的网络应用程序的文件?
本质上,如何下载/流/管道在经过一段时间后加载的可下载资源,而不是通过直接下载链接。
我以为我可以用Zombie.js Pipeline做到这一点......但对于一个zombiejs新手来说,这些文档是毫无意义的
答案 0 :(得分:0)
不确定这是否会对你有所帮助,但这有助于我抓住回复机构。 (从GitHub issue复制。)
async
答案 1 :(得分:0)
可用于下载 BINARY FILES
var fs = require('fs');
var URL = require('url');
var Request = require('request'); // Named 'Request' to prevent conflict with zombie's 'request' object
var Browser = require('zombie'), browser = new Browser();
browser.on('request', function (request) {
// let's pullover for a download incase we find our request signboard :)
if (request.url.indexOf('https://matchingString') == 0) {
console.log('Beginning download in a flash...');
var
parsedURL = URL.parse(request.url),
cookies = browser.cookies,
cookieHeader = cookies.serialize(parsedURL.hostname, parsedURL.pathname);
if (cookieHeader) request.headers.append('Cookie', cookieHeader);
var writeStream = fs.createWriteStream(pathToFileYetToBeWritten);
writeStream
.on('error', function(err) {
console.error(err);
})
.on('finish', function() {
console.log('finished writing file');
});
Request({
method: request.method,
uri: request.url,
headers: request.headers.toObject(),
proxy: browser.proxy,
body: request.body,
jar: false,
followRedirect: false,
strictSSL: browser.strictSSL,
localAddress: browser.localAddress || 0
})
.on('error', function(err) {
console.error(err);
})
.pipe(writeStream);
}
});
browser.visit(url, function () {
browser.wait(6000); // Wait only if you need to
});