Skip to content

Instantly share code, notes, and snippets.

@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;
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 / 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){
// 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 / 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
@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 / gist:a84e915f05b03cf19bdc
Created November 25, 2014 14:00
nightmareDownload.js
var useOldDownloadWay = false;
var Nightmare = require('nightmare');
new Nightmare()
.goto('http://eprint.iacr.org/2004/152')
.evaluate(function ev(old){
var el = document.querySelector("[href*='.pdf']");
var xhr = new XMLHttpRequest();
xhr.open("GET", el.href, false);
if (old) {
var page = require('webpage').create();
var url = 'http://api.jquery.com/jQuery.ajax/';
page.open(url, function (status) {
var result = page.evaluate(function(url){
var result = "blah";
$.ajax({
async: false,
url: "/",
type: 'get',
@artjomb
artjomb / infiniteScroll_1.py
Last active June 12, 2023 00:00
infinite scroll of stackstatus with python in phantomjs
import selenium
import time
from selenium import webdriver
browser = webdriver.PhantomJS("phantomjs")
browser.get("https://twitter.com/StackStatus")
print browser.title
pause = 3