mirror of https://github.com/vitalif/phantomjs
Updated examples to use "require('webpage').create()" instead of "new WebPage()".
parent
e960279ff2
commit
e0e5535e0e
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
page.viewportSize = { width: 400, height : 400 }
|
page.viewportSize = { width: 400, height : 400 }
|
||||||
page.content = '<html><body><canvas id="surface"></canvas></body></html>'
|
page.content = '<html><body><canvas id="surface"></canvas></body></html>'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage;
|
var page = require('webpage').create();
|
||||||
page.viewportSize = { width: 400, height : 400 };
|
page.viewportSize = { width: 400, height : 400 };
|
||||||
page.content = '<html><body><canvas id="surface"></canvas></body></html>';
|
page.content = '<html><body><canvas id="surface"></canvas></body></html>';
|
||||||
page.evaluate(function() {
|
page.evaluate(function() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Get driving direction using Google Directions API.
|
# Get driving direction using Google Directions API.
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
if phantom.args.length < 2
|
if phantom.args.length < 2
|
||||||
console.log 'Usage: direction.js origin destination'
|
console.log 'Usage: direction.js origin destination'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Get driving direction using Google Directions API.
|
// Get driving direction using Google Directions API.
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
origin, dest, steps;
|
origin, dest, steps;
|
||||||
|
|
||||||
if (phantom.args.length < 2) {
|
if (phantom.args.length < 2) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ users= [
|
||||||
]
|
]
|
||||||
|
|
||||||
follow = (user, callback) ->
|
follow = (user, callback) ->
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
page.open 'http://mobile.twitter.com/' + user, (status) ->
|
page.open 'http://mobile.twitter.com/' + user, (status) ->
|
||||||
if status is 'fail'
|
if status is 'fail'
|
||||||
console.log user + ': ?'
|
console.log user + ': ?'
|
||||||
|
|
|
@ -28,7 +28,7 @@ var users = ['sencha',
|
||||||
'whereisthysting'];
|
'whereisthysting'];
|
||||||
|
|
||||||
function follow(user, callback) {
|
function follow(user, callback) {
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
page.open('http://mobile.twitter.com/' + user, function (status) {
|
page.open('http://mobile.twitter.com/' + user, function (status) {
|
||||||
if (status === 'fail') {
|
if (status === 'fail') {
|
||||||
console.log(user + ': ?');
|
console.log(user + ': ?');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Upload an image to imagebin.org
|
# Upload an image to imagebin.org
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
if phantom.args.length isnt 1
|
if phantom.args.length isnt 1
|
||||||
console.log 'Usage: imagebin.coffee filename'
|
console.log 'Usage: imagebin.coffee filename'
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Upload an image to imagebin.org
|
// Upload an image to imagebin.org
|
||||||
|
|
||||||
var page = new WebPage(), fname;
|
var page = require('webpage').create(),
|
||||||
|
fname;
|
||||||
|
|
||||||
if (phantom.args.length !== 1) {
|
if (phantom.args.length !== 1) {
|
||||||
console.log('Usage: imagebin.js filename');
|
console.log('Usage: imagebin.js filename');
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Use 'page.injectJs()' to load the script itself in the Page context
|
# Use 'page.injectJs()' to load the script itself in the Page context
|
||||||
|
|
||||||
if phantom?
|
if phantom?
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main
|
# Route "console.log()" calls from within the Page context to the main
|
||||||
# Phantom context (i.e. current "this")
|
# Phantom context (i.e. current "this")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Use 'page.injectJs()' to load the script itself in the Page context
|
// Use 'page.injectJs()' to load the script itself in the Page context
|
||||||
|
|
||||||
if ( typeof(phantom) !== "undefined" ) {
|
if ( typeof(phantom) !== "undefined" ) {
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
page.onConsoleMessage = function(msg) {
|
page.onConsoleMessage = function(msg) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
if phantom.args.length is 0
|
if phantom.args.length is 0
|
||||||
console.log 'Usage: loadspeed.js <some URL>'
|
console.log 'Usage: loadspeed.js <some URL>'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
t, address;
|
t, address;
|
||||||
|
|
||||||
if (phantom.args.length === 0) {
|
if (phantom.args.length === 0) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
address = phantom.args[0]
|
address = phantom.args[0]
|
||||||
|
|
||||||
if phantom.args.length is 0
|
if phantom.args.length is 0
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
address = phantom.args[0];
|
address = phantom.args[0];
|
||||||
|
|
||||||
if (phantom.args.length === 0) {
|
if (phantom.args.length === 0) {
|
||||||
|
|
|
@ -73,7 +73,7 @@ createHAR = (address, title, startTime, resources) ->
|
||||||
]
|
]
|
||||||
entries: entries
|
entries: entries
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
if phantom.args.length is 0
|
if phantom.args.length is 0
|
||||||
console.log 'Usage: netsniff.js <some URL>'
|
console.log 'Usage: netsniff.js <some URL>'
|
||||||
|
|
|
@ -84,7 +84,7 @@ function createHAR(address, title, startTime, resources)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
if (phantom.args.length === 0) {
|
if (phantom.args.length === 0) {
|
||||||
console.log('Usage: netsniff.js <some URL>');
|
console.log('Usage: netsniff.js <some URL>');
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
# Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
page.onConsoleMessage = (msg) -> console.log msg
|
page.onConsoleMessage = (msg) -> console.log msg
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
page.onConsoleMessage = function(msg) {
|
page.onConsoleMessage = function(msg) {
|
||||||
console.log(msg);
|
console.log(msg);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Find pizza in Mountain View using Yelp
|
# Find pizza in Mountain View using Yelp
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search'
|
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search'
|
||||||
|
|
||||||
page.open url,
|
page.open url,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Find pizza in Mountain View using Yelp
|
// Find pizza in Mountain View using Yelp
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search';
|
url = 'http://lite.yelp.com/search?find_desc=pizza&find_loc=94040&find_submit=Search';
|
||||||
|
|
||||||
page.open(url, function (status) {
|
page.open(url, function (status) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Example using HTTP POST operation
|
# Example using HTTP POST operation
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
server = 'http://posttestserver.com/post.php?dump'
|
server = 'http://posttestserver.com/post.php?dump'
|
||||||
data = 'universe=expanding&answer=42'
|
data = 'universe=expanding&answer=42'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Example using HTTP POST operation
|
// Example using HTTP POST operation
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
server = 'http://posttestserver.com/post.php?dump',
|
server = 'http://posttestserver.com/post.php?dump',
|
||||||
data = 'universe=expanding&answer=42';
|
data = 'universe=expanding&answer=42';
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
if phantom.args.length < 2 or phantom.args.length > 3
|
if phantom.args.length < 2 or phantom.args.length > 3
|
||||||
console.log 'Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'
|
console.log 'Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
address, output, size;
|
address, output, size;
|
||||||
|
|
||||||
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
||||||
|
|
|
@ -11,7 +11,7 @@ Array.prototype.forEach = (action) ->
|
||||||
# @param file File to render to
|
# @param file File to render to
|
||||||
# @param callback Callback function
|
# @param callback Callback function
|
||||||
renderUrlToFile = (url, file, callback) ->
|
renderUrlToFile = (url, file, callback) ->
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
page.viewportSize = { width: 800, height : 600 }
|
page.viewportSize = { width: 800, height : 600 }
|
||||||
page.settings.userAgent = 'Phantom.js bot'
|
page.settings.userAgent = 'Phantom.js bot'
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ Array.prototype.forEach = function (action) {
|
||||||
* @param callback Callback function
|
* @param callback Callback function
|
||||||
*/
|
*/
|
||||||
function renderUrlToFile(url, file, callback) {
|
function renderUrlToFile(url, file, callback) {
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
page.viewportSize = { width: 800, height : 600 };
|
page.viewportSize = { width: 800, height : 600 };
|
||||||
page.settings.userAgent = "Phantom.js bot";
|
page.settings.userAgent = "Phantom.js bot";
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ if phantom.args.length isnt 1
|
||||||
console.log 'Usage: run-jasmine.coffee URL'
|
console.log 'Usage: run-jasmine.coffee URL'
|
||||||
phantom.exit()
|
phantom.exit()
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
page.onConsoleMessage = (msg) ->
|
page.onConsoleMessage = (msg) ->
|
||||||
|
|
|
@ -39,7 +39,7 @@ if (phantom.args.length === 0 || phantom.args.length > 2) {
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
page.onConsoleMessage = function(msg) {
|
page.onConsoleMessage = function(msg) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ if phantom.args.length isnt 1
|
||||||
console.log 'Usage: run-qunit.coffee URL'
|
console.log 'Usage: run-qunit.coffee URL'
|
||||||
phantom.exit(1)
|
phantom.exit(1)
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
page.onConsoleMessage = (msg) ->
|
page.onConsoleMessage = (msg) ->
|
||||||
|
|
|
@ -39,7 +39,7 @@ if (phantom.args.length === 0 || phantom.args.length > 2) {
|
||||||
phantom.exit(1);
|
phantom.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
page.onConsoleMessage = function(msg) {
|
page.onConsoleMessage = function(msg) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
page.viewportSize = { width: 320, height: 480 }
|
page.viewportSize = { width: 320, height: 480 }
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
page.viewportSize = { width: 320, height: 480 };
|
page.viewportSize = { width: 320, height: 480 };
|
||||||
page.open('http://news.google.com/news/i/section?&topic=t', function (status) {
|
page.open('http://news.google.com/news/i/section?&topic=t', function (status) {
|
||||||
if (status !== 'success') {
|
if (status !== 'success') {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Get twitter status for given account (or for the default one, "sencha")
|
# Get twitter status for given account (or for the default one, "sencha")
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
twitterId = 'sencha' #< default value
|
twitterId = 'sencha' #< default value
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Get twitter status for given account (or for the default one, "sencha")
|
// Get twitter status for given account (or for the default one, "sencha")
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
twitterId = "sencha"; //< default value
|
twitterId = "sencha"; //< default value
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Modify global object at the page initialization.
|
# Modify global object at the page initialization.
|
||||||
# In this example, effectively Math.random() always returns 0.42.
|
# In this example, effectively Math.random() always returns 0.42.
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
page.onInitialized = ->
|
page.onInitialized = ->
|
||||||
page.evaluate ->
|
page.evaluate ->
|
||||||
Math.random = ->
|
Math.random = ->
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Modify global object at the page initialization.
|
// Modify global object at the page initialization.
|
||||||
// In this example, effectively Math.random() always returns 0.42.
|
// In this example, effectively Math.random() always returns 0.42.
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
page.onInitialized = function () {
|
page.onInitialized = function () {
|
||||||
page.evaluate(function () {
|
page.evaluate(function () {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
console.log 'The default user agent is ' + page.settings.userAgent
|
console.log 'The default user agent is ' + page.settings.userAgent
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
console.log('The default user agent is ' + page.settings.userAgent);
|
console.log('The default user agent is ' + page.settings.userAgent);
|
||||||
page.settings.userAgent = 'SpecialAgent';
|
page.settings.userAgent = 'SpecialAgent';
|
||||||
page.open('http://www.httpuseragent.org', function (status) {
|
page.open('http://www.httpuseragent.org', function (status) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ waitFor = (testFx, onReady, timeOutMillis=3000) ->
|
||||||
interval = setInterval f, 250 #< repeat check every 250ms
|
interval = setInterval f, 250 #< repeat check every 250ms
|
||||||
|
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
|
|
||||||
# Open Twitter on 'sencha' profile and, onPageLoad, do...
|
# Open Twitter on 'sencha' profile and, onPageLoad, do...
|
||||||
page.open 'http://twitter.com/#!/sencha', (status) ->
|
page.open 'http://twitter.com/#!/sencha', (status) ->
|
||||||
|
|
|
@ -34,7 +34,7 @@ function waitFor(testFx, onReady, timeOutMillis) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
var page = new WebPage();
|
var page = require('webpage').create();
|
||||||
|
|
||||||
// Open Twitter on 'sencha' profile and, onPageLoad, do...
|
// Open Twitter on 'sencha' profile and, onPageLoad, do...
|
||||||
page.open("http://twitter.com/#!/sencha", function (status) {
|
page.open("http://twitter.com/#!/sencha", function (status) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Get weather info for given address (or for the default one, "Mountain View")
|
# Get weather info for given address (or for the default one, "Mountain View")
|
||||||
|
|
||||||
page = new WebPage()
|
page = require('webpage').create()
|
||||||
address = 'Mountain View' #< default value
|
address = 'Mountain View' #< default value
|
||||||
|
|
||||||
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
# Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Get weather info for given address (or for the default one, "Mountain View")
|
// Get weather info for given address (or for the default one, "Mountain View")
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = require('webpage').create(),
|
||||||
address = "Mountain View"; //< default value
|
address = "Mountain View"; //< default value
|
||||||
|
|
||||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||||
|
|
Loading…
Reference in New Issue