从JS生成的链接下载PDF

时间:2019-07-10 07:59:29

标签: download casperjs google-chrome-headless headless-browser

我正在尝试从网站下载PDF。链接是由JS生成的,我能够收集URL。如何告诉无头浏览器在这些链接上单击点击并下载文件?

var casper = require('casper').create();
var links;
var fs = require('fs');

function getLinks() {
  links = document.querySelectorAll('.skb-dabslink a');

  return Array.prototype.map.call(links, function (e) {
    return e.getAttribute('href')
  });
}

casper.start('https://www.skybriefing.com/portal/dabs');

casper.wait(5000) ; //Waiting for the links to display

casper.then(function () {
  links = this.evaluate(getLinks);
});

casper.then(function () {
  for(var i in links) {
    console.log(links[i]);
  }
});

casper.then(function () {
  console.log(fs) ;
  fs.write("links.txt", links, 'w');
})

casper.run()

0 个答案:

没有答案