Skip to content

Instantly share code, notes, and snippets.

@artjomb
artjomb / PhantomJS1.x_useragentstring
Created November 10, 2014 13:11
This user agent string corresponds to the same features that PhantomJS provides.
Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1
@artjomb
artjomb / result
Last active August 29, 2015 14:08
Small testing file for CasperJS (test environment) to see when the test suite is stopped executing
E:\shared\temp\casper>Test file: test90.js
# test w/o wait
FAIL test false
# type: assert
# file: test90.js:5
# code: test.assert(false, "test false");
# subject: false
PASS test true
# test w/ wait
FAIL test false
// Run as: casperjs --cookies-file=cookies.txt SE_get_close_votes.js
// to skip logging in the next time or simply: casperjs SE_get_close_votes.js
// Don't forget to input your credentials
// The login is not perfect, so it might fail. Just try again.
var casper = require('casper').create({
viewportSize: {
width: 1280,
height: 800
},
@artjomb
artjomb / benchmark.js
Last active August 29, 2015 14:06
Test PhantomJS 1.9.7 selectors API speed for a huge DOM
var page = require('webpage').create();
var content = "",
max = 100000,
i;
for(i = 0; i < max; i++) {
content += '<form id="f' + i + '"><input type="hidden" name="in' + i + '" valuate"iv' + i + '"></form>';
}
page.evaluate(function(content){
var casper = require('casper').create();
var url = "http://example.com/";
casper.start().thenOpen(url).then(function() {
this.download(url, "example.html");
this.page.customHeaders = {
"Accept-Language": "hu"
};
}).thenOpen(url).then(function() {
@artjomb
artjomb / fsOverwrite.js
Last active August 29, 2015 14:05
phantomjs fs.overwrite
var fs = require('fs');
fs.overwrite = function(source, destination, maxTrials){
var overwritten = false;
var trials = 0;
maxTrials = parseInt(maxTrials)
maxTrials = !!maxTrials ? maxTrials : null;
while(!overwritten) {
if (maxTrials && trials > maxTrials) {
return -1;