【问题标题】:Download a file with PhantomJs使用 PhantomJs 下载文件
【发布时间】:2016-12-12 08:48:16
【问题描述】:

我正在尝试使用 PhantomJs 无头浏览器下载文件。我必须按下才能开始下载的按钮是 Javascript 形式的。我不知道如何处理下载对话框,也找不到有关它的文档。

我需要登录才能执行下载。

有没有人提供关于这种行为的信息?

【问题讨论】:

  • 接受正确答案在 StackOverflow 上被认为是礼貌的。如果答案解决了您的问题,只需单击投票按钮附近的灰色复选框。它还会激励其他人帮助你。

标签: python python-2.7 phantomjs headless


【解决方案1】:

尝试将此代码放在按钮单击事件中,或者可以使用此原始代码来获取它:

var page = require('webpage').create();

page.settings.userName = 'your username here';

page.settings.password = 'your password here';

 var url = "your url comes here";
 var fs = require('fs');
 var path = 'index.html'; //here you can use a format of the file you want .json .txt etc.

 page.open(url, function (status) {
     if(status !== 'success') {
         console.log('Connection failed, page was not loaded!');
     } else {
         var content = page.content;
         fs.write(path,content,'w')
         phantom.exit();
     }
});

另外,请查看此链接How to download a csv file using PhantomJS

如果您需要进一步的帮助,请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-12
    • 2016-12-15
    • 2017-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多