Hack Forums
[Java] Changing user agent in PhantomJS - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Changing user agent in PhantomJS (/showthread.php?tid=5797609)



Changing user agent in PhantomJS - milknpepper - Feb 10, 2018

How does one change user agent in the following simple phantomjs script:


Code
var page = new WebPage()
   var fs = require('fs');


   page.onLoadFinished = function() {
     console.log("page load finished");
     fs.write('1.html', page.content, 'w');
     phantom.exit();
   };

   page.open("link here i took away...", function() {
     page.evaluate(function() {
     });
   });


Found solution.

var page = require('webpage').create();
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36';
page.open('asdgsgsdgsdge/', function() {
window.setTimeout(function() {
var output = page.evaluate(function() {
return document.getElementById('tournamentTable')
.getElementsByClassName('deactivate')[0]
.getElementsByTagName('a')[0]
.textContent;
});
console.log(output);
}, 1000);
});