Created
December 15, 2016 15:43
-
-
Save jnsprnw/bcf866f04d08fc4d5137fd6e9bef3b0c to your computer and use it in GitHub Desktop.
PhantomJS setup for hiding Phantomjs fingerprint
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
"use strict"; | |
var page = require('webpage').create(); | |
page.onConsoleMessage = function (msg) { | |
console.log('Console.log: ' + msg); | |
}; | |
page.onError = function (msg) { | |
console.log('Error: ' + msg); | |
}; | |
var url = 'https://www.crunchbase.com/organization/stripe/investors'; | |
console.log('Scraping ' + url); | |
var version = Math.floor(Math.random() * 30) + 20; | |
var fakeUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.' + Math.floor(Math.random() * 5) + 5 + '; rv:' + version + '.0) Gecko/20100101 Firefox/' + version + '.0'; | |
page.settings.userAgent = fakeUserAgent; | |
page.settings.javascriptEnabled = true; | |
page.settings.loadImages = false; | |
page.viewportSize = { | |
width: Math.floor(Math.random() * 800) + 480, | |
height: Math.floor(Math.random() * 400) + 600 | |
} | |
page.onResourceRequested = function(requestData, networkRequest) { | |
var match = requestData.url.match(/strangeScript/g); | |
if (match != null) { | |
console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData)); | |
networkRequest.changeUrl('evenStrangerScript.js'); | |
} | |
}; | |
page.onInitialized = function() { | |
console.log('onInitialized') | |
page.evaluate(function() { | |
(function() { | |
var userAgent = window.navigator.userAgent, | |
platform = window.navigator.platform; | |
var version = Math.floor(Math.random() * 30) + 20; | |
var fakeUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.' + Math.floor(Math.random() * 5) + 5 + '; rv:' + version + '.0) Gecko/20100101 Firefox/' + version + '.0'; | |
window.navigator = { | |
appCodeName: 'Mozilla', | |
appName: "Netscape", | |
cookieEnabled: true, | |
plugins: {"0":{"0":{},"name":"AdobeAAMDetect","filename":"AdobeAAMDetect.plugin","description":"Creative Cloud Desktop Plugin.v_3_0_0_0","length":1},"1":{"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"name":"Adobe Acrobat NPAPI Plug-in, Version 15.020.20042","filename":"AdobePDFViewerNPAPI.plugin","description":"Adobe® Acrobat® Plug-in for Web Browsers, Version 15.020.20042","length":8},"2":{"0":{},"name":"Default Browser Helper","filename":"Default Browser.plugin","description":"Bietet Informationen über den Standardwebbrowser","length":1},"3":{"0":{},"name":"Google Earth Plug-in","filename":"Google Earth Web Plug-in.plugin","description":"The Google Earth Plugin allows you to view 3D imagery and terrain in your web browser.","length":1},"4":{"0":{},"1":{},"name":"SharePoint Browser Plug-in","filename":"SharePointBrowserPlugin.plugin","description":"Microsoft Office for Mac SharePoint Browser Plug-in","length":2},"5":{"0":{},"name":"WacomTabletPlugin","filename":"WacomTabletPlugin.plugin","description":"Plugin for Wacom tablets.","length":1},"6":{"0":{},"1":{},"2":{},"name":"WebKit-integrierte PDF","filename":"","description":"","length":3},"length":7}, | |
sniffedUserAgent: false, | |
userAgent: fakeUserAgent, | |
language: "en-en", | |
productSub: "20030107", | |
mimeTypes: {"0":{},"1":{},"2":{},"3":{},"4":{},"5":{},"6":{},"7":{},"8":{},"9":{},"10":{},"11":{},"12":{},"13":{},"14":{},"15":{},"16":{},"17":{},"18":{},"19":{},"20":{},"21":{},"22":{},"23":{},"24":{},"25":{},"26":{},"27":{},"28":{},"application/apple-default-browser":{},"application/futuresplash":{},"application/geplugin":{},"application/x-adobeaamdetect":{},"application/x-java-applet":{},"application/x-java-applet;deploy=11.74.2":{},"application/x-java-applet;javafx=8.0.72":{},"application/x-java-applet;jpi-version=1.8.0_74":{},"application/x-java-applet;version=1.1":{},"application/x-java-applet;version=1.1.1":{},"application/x-java-applet;version=1.1.2":{},"application/x-java-applet;version=1.1.3":{},"application/x-java-applet;version=1.2":{},"application/x-java-applet;version=1.2.1":{},"application/x-java-applet;version=1.2.2":{},"application/x-java-applet;version=1.3":{},"application/x-java-applet;version=1.3.1":{},"application/x-java-applet;version=1.4":{},"application/x-java-applet;version=1.4.1":{},"application/x-java-applet;version=1.4.2":{},"application/x-java-applet;version=1.5":{},"application/x-java-applet;version=1.6":{},"application/x-java-applet;version=1.7":{},"application/x-java-applet;version=1.8":{},"application/x-java-vm":{},"application/x-sharepoint":{},"application/x-sharepoint-protocolhandler":{},"application/x-shockwave-flash":{},"application/x-wacomtabletplugin":{}} | |
}; | |
})(); | |
}); | |
}; | |
page.open(url, function (status) { | |
console.log('Status: Success'); | |
if (status === 'success') { | |
window.setTimeout(function () { | |
page.render('screenshot.png'); | |
if (page.injectJs('jquery.min.js')) { | |
var h1 = page.evaluate( function () { | |
return $("h1").text(); | |
}); | |
console.log("H1:" + h1); | |
} | |
phantom.exit(0); | |
}, 500 + 500 * Math.random()); | |
} else { | |
phantom.exit(1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is sniffedUserAgent: false? Google has no other result than your script... false means it exists so certainly not a good idea.