Created
June 19, 2015 19:50
-
-
Save franklinjavier/8941facbef0da8211101 to your computer and use it in GitHub Desktop.
How to generate pageview with casperjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * How to generate pageview with casperjs | |
| * | |
| * How to use: | |
| * | |
| * 1. npm i -g phantomjs casperjs | |
| * 2. casperjs ddos.js [number] [url] | |
| * | |
| * number - number of pageview | |
| * url - url to generate pageview | |
| * | |
| */ | |
| 'user stritct'; | |
| var casper = require('casper').create({ | |
| waitTimeout: 30000, | |
| pageSettings: { | |
| loadImages: true, | |
| loadPlugins: true | |
| }, | |
| onLoadError: function() { | |
| log('Bad request'); | |
| }, | |
| onError: function(self, m) { | |
| console.log(' - Phantom Error: ' + m); | |
| }, | |
| onStepTimeout: function(self,m){ | |
| console.log(' - Timeout: step ' + m); | |
| } | |
| }), | |
| i = 0, | |
| len = casper.cli.args[0] || 300, | |
| url = casper.cli.args[1] || 'http://google.com'; | |
| casper.start(); | |
| function log( msg ) { | |
| console.log(msg); | |
| } | |
| function getFirstLink() { | |
| return document.querySelectorAll('a')[0].innerText; | |
| } | |
| for ( ; i < len; i++ ) { | |
| casper.thenOpen( url, function(){ | |
| this.echo(this.evaluate( getFirstLink )); | |
| }); | |
| } | |
| casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment