【问题标题】:CasperJS upload image from url instead of server pathCasperJS从url而不是服务器路径上传图片
【发布时间】:2017-09-26 13:25:25
【问题描述】:

我正在使用 CasperJS 来完成我的自动化工作。但是对于文件上传,我使用exec()wget从其他网站上传图片到我的服务器,然后使用CasperJS和casper.uploadFile()在网站上发布图片。

现在我尝试使用网站图片 URL 发布图片,我的意思是:

casper.then(function(){
    this.uploadFile("input[type='file']", '/var/tmp/img.jpg');
})

但我想做:

casper.then(function(){
    this.uploadFile("input[type='file']", 'http://mywebsite.com/images/img.jpg');
})

当我这样做时,Casper 失败了。

【问题讨论】:

  • 你自己可能已经猜到了,它是行不通的。填写上传字段时,浏览器使用本地文件。
  • 是的,没错,我只是认为存在类似于读写流的东西,就像我们在 Node 本身中所拥有的那样。

标签: phantomjs casperjs


【解决方案1】:

为什么不先下载图片再上传呢?

casper.then(function() {
  this.download("http://mywebsite.com/images/img.jpg", 'd:/_tmp/img.jpg');
}

casper.then(function(){
  this.uploadFile("input[type='file']", 'd:/_tmp/img.jpg');
})

请参阅文档中的 download

【讨论】:

    猜你喜欢
    • 2018-01-01
    • 2018-03-21
    • 2011-07-23
    • 1970-01-01
    • 2021-11-09
    • 1970-01-01
    • 1970-01-01
    • 2014-06-08
    • 2012-02-19
    相关资源
    最近更新 更多