casperjs批量执行多个url

mac2022-06-30  21

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();

 

转载于:https://www.cnblogs.com/c-x-a/p/7267400.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)