Search code examples
javascriptphantomjscasperjs

Multiple Post request CasperJS


I'm a beginner programmer in JavaScript and CasperJS and I'm hoping to make multiple post requests.

casper.then(function(){

  for(var i=0; i<30; i++){
        casper.open(address, {      
           method: 'post',
           data:   {
              'title': 'Hello',
              'body':  'Hello World ...'
           }
        });
    casper.back();
  }

});

Solution

  • First, you need to make sure that address is a full URL (with http:// and everything). Second, you need to use casper.thenOpen() instead of casper.open(), because the loop is too fast for casper.open() to be executed. Instead, it will overwrite multiple requests.