-
-
Save wellsie/956efc8c927f8e01f84b to your computer and use it in GitHub Desktop.
This file contains 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
var casper = require('casper').create(); | |
var webpage = "http://wordpress.org/"; | |
casper.on('resource.requested', function(resource) { | |
for (var obj in resource.headers) { | |
var name = resource.headers[obj].name; | |
var value = resource.headers[obj].value; | |
if (name == "User-Agent"){ | |
this.echo(value); | |
} | |
} | |
}); | |
casper.start(); | |
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)'); | |
casper.thenOpen('http://google.com/', function() { | |
this.echo("I'm a Mac."); | |
}); | |
this.userAgent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); | |
this.thenOpen('http://google.com/', function() { | |
this.echo("I'm a PC."); | |
}); | |
casper.run(); | |
/* | |
//OUTPUT: does not work, last user-agent string used for both runs | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
I'm a Mac. | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
I'm a PC. | |
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment