casperjs批量执行多个url

Posted 一起来学python

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了casperjs批量执行多个url相关的知识,希望对你有一定的参考价值。

var fs=require("fs");

//
//-------sample.js-------
//

//casperオブジェクトを生成
var casper = require(‘casper‘).create();
casper.start();
//指定のURLへ遷移する
casper.thenOpen(‘http://www.yahoo.co.jp‘, function() {

fs.write("6661.html",this.getHTML(),‘w‘);
require(‘utils‘).dump(document.URL);
});
casper.thenOpen(‘http://www.yahoo.co.jp‘, function() {

fs.write("6662.html",this.getHTML(),‘w‘);
require(‘utils‘).dump(document.URL);
});
casper.thenOpen(‘http://www.yahoo.co.jp‘, function() {

fs.write("6663.html",this.getHTML(),‘w‘);
require(‘utils‘).dump(document.URL);
});
casper.thenOpen(‘http://www.yahoo.co.jp‘, function() {

fs.write("6664.html",this.getHTML(),‘w‘);
require(‘utils‘).dump(document.URL);
});
casper.thenOpen(‘http://www.yahoo.co.jp‘, function() {

fs.write("6665.html",this.getHTML(),‘w‘);
require(‘utils‘).dump(document.URL);
});

//処理の実行
casper.run();

---------------以上可以简写-------------------------------------

var fs=require(‘fs‘);
var casper = require(‘casper‘).create();
var urls = [‘http://google.com/‘, ‘http://yahoo.com/‘];
index=0;
casper.start().eachThen(urls, function(response) {
index++;
this.thenOpen(response.data, function(response) {
fs.write("6666_"+index+".html",this.getHTML(),‘w‘);
});
});


casper.run();

 

以上是关于casperjs批量执行多个url的主要内容,如果未能解决你的问题,请参考以下文章

shell批量执行多个shell脚本

MongoDB怎样批量执行命令

oracle如何批量执行某个文件夹下面的多个.sql脚本

批量执行多个SQL文件

如何在spring boot jdbc中从具有批量大小的多个表中执行批量删除

如何在 r2dbc 中批量执行多个插入?