Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
REMitchell
GitHub Repository: REMitchell/python-crawling
Path: blob/master/6-Selenium/phantomjs/examples/unrandomize.js
164 views
1
// Modify global object at the page initialization.
2
// In this example, effectively Math.random() always returns 0.42.
3
4
var page = require('webpage').create();
5
6
page.onInitialized = function () {
7
page.evaluate(function () {
8
Math.random = function() {
9
return 42 / 100;
10
};
11
});
12
};
13
14
page.open('http://ariya.github.com/js/random/', function (status) {
15
var result;
16
if (status !== 'success') {
17
console.log('Network error.');
18
} else {
19
console.log(page.evaluate(function () {
20
return document.getElementById('numbers').textContent;
21
}));
22
}
23
phantom.exit();
24
});
25
26