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.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.content = '<html><body><canvas id="surface"></canvas></body></html>';
|
||||
page.evaluate(function() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Get driving direction using Google Directions API.
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
if phantom.args.length < 2
|
||||
console.log 'Usage: direction.js origin destination'
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Get driving direction using Google Directions API.
|
||||
|
||||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
origin, dest, steps;
|
||||
|
||||
if (phantom.args.length < 2) {
|
||||
|
|
|
@ -30,7 +30,7 @@ users= [
|
|||
]
|
||||
|
||||
follow = (user, callback) ->
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
page.open 'http://mobile.twitter.com/' + user, (status) ->
|
||||
if status is 'fail'
|
||||
console.log user + ': ?'
|
||||
|
|
|
@ -28,7 +28,7 @@ var users = ['sencha',
|
|||
'whereisthysting'];
|
||||
|
||||
function follow(user, callback) {
|
||||
var page = new WebPage();
|
||||
var page = require('webpage').create();
|
||||
page.open('http://mobile.twitter.com/' + user, function (status) {
|
||||
if (status === 'fail') {
|
||||
console.log(user + ': ?');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Upload an image to imagebin.org
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
if phantom.args.length isnt 1
|
||||
console.log 'Usage: imagebin.coffee filename'
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Upload an image to imagebin.org
|
||||
|
||||
var page = new WebPage(), fname;
|
||||
var page = require('webpage').create(),
|
||||
fname;
|
||||
|
||||
if (phantom.args.length !== 1) {
|
||||
console.log('Usage: imagebin.js filename');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Use 'page.injectJs()' to load the script itself in the Page context
|
||||
|
||||
if phantom?
|
||||
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")
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Use 'page.injectJs()' to load the script itself in the Page context
|
||||
|
||||
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")
|
||||
page.onConsoleMessage = function(msg) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
if phantom.args.length is 0
|
||||
console.log 'Usage: loadspeed.js <some URL>'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
t, address;
|
||||
|
||||
if (phantom.args.length === 0) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
address = phantom.args[0]
|
||||
|
||||
if phantom.args.length is 0
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
address = phantom.args[0];
|
||||
|
||||
if (phantom.args.length === 0) {
|
||||
|
|
|
@ -73,7 +73,7 @@ createHAR = (address, title, startTime, resources) ->
|
|||
]
|
||||
entries: entries
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
if phantom.args.length is 0
|
||||
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) {
|
||||
console.log('Usage: netsniff.js <some URL>');
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
page.onConsoleMessage = (msg) -> console.log msg
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Read the Phantom webpage '#intro' element text using jQuery and "includeJs"
|
||||
|
||||
var page = new WebPage();
|
||||
var page = require('webpage').create();
|
||||
|
||||
page.onConsoleMessage = function(msg) {
|
||||
console.log(msg);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# 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'
|
||||
|
||||
page.open url,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// 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';
|
||||
|
||||
page.open(url, function (status) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Example using HTTP POST operation
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
server = 'http://posttestserver.com/post.php?dump'
|
||||
data = 'universe=expanding&answer=42'
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Example using HTTP POST operation
|
||||
|
||||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
server = 'http://posttestserver.com/post.php?dump',
|
||||
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
|
||||
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;
|
||||
|
||||
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
||||
|
|
|
@ -11,7 +11,7 @@ Array.prototype.forEach = (action) ->
|
|||
# @param file File to render to
|
||||
# @param callback Callback function
|
||||
renderUrlToFile = (url, file, callback) ->
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
page.viewportSize = { width: 800, height : 600 }
|
||||
page.settings.userAgent = 'Phantom.js bot'
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ Array.prototype.forEach = function (action) {
|
|||
* @param callback Callback function
|
||||
*/
|
||||
function renderUrlToFile(url, file, callback) {
|
||||
var page = new WebPage();
|
||||
var page = require('webpage').create();
|
||||
page.viewportSize = { width: 800, height : 600 };
|
||||
page.settings.userAgent = "Phantom.js bot";
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ if phantom.args.length isnt 1
|
|||
console.log 'Usage: run-jasmine.coffee URL'
|
||||
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")
|
||||
page.onConsoleMessage = (msg) ->
|
||||
|
|
|
@ -39,7 +39,7 @@ if (phantom.args.length === 0 || phantom.args.length > 2) {
|
|||
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")
|
||||
page.onConsoleMessage = function(msg) {
|
||||
|
|
|
@ -33,7 +33,7 @@ if phantom.args.length isnt 1
|
|||
console.log 'Usage: run-qunit.coffee URL'
|
||||
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")
|
||||
page.onConsoleMessage = (msg) ->
|
||||
|
|
|
@ -39,7 +39,7 @@ if (phantom.args.length === 0 || phantom.args.length > 2) {
|
|||
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")
|
||||
page.onConsoleMessage = function(msg) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
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.open('http://news.google.com/news/i/section?&topic=t', function (status) {
|
||||
if (status !== 'success') {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Get twitter status for given account (or for the default one, "sencha")
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
twitterId = 'sencha' #< default value
|
||||
|
||||
# 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")
|
||||
|
||||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
twitterId = "sencha"; //< default value
|
||||
|
||||
// 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.
|
||||
# In this example, effectively Math.random() always returns 0.42.
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
page.onInitialized = ->
|
||||
page.evaluate ->
|
||||
Math.random = ->
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Modify global object at the page initialization.
|
||||
// In this example, effectively Math.random() always returns 0.42.
|
||||
|
||||
var page = new WebPage();
|
||||
var page = require('webpage').create();
|
||||
|
||||
page.onInitialized = 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
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var page = new WebPage();
|
||||
var page = require('webpage').create();
|
||||
console.log('The default user agent is ' + page.settings.userAgent);
|
||||
page.settings.userAgent = 'SpecialAgent';
|
||||
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
|
||||
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
|
||||
# Open Twitter on 'sencha' profile and, onPageLoad, do...
|
||||
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...
|
||||
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")
|
||||
|
||||
page = new WebPage()
|
||||
page = require('webpage').create()
|
||||
address = 'Mountain View' #< default value
|
||||
|
||||
# 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")
|
||||
|
||||
var page = new WebPage(),
|
||||
var page = require('webpage').create(),
|
||||
address = "Mountain View"; //< default value
|
||||
|
||||
// Route "console.log()" calls from within the Page context to the main Phantom context (i.e. current "this")
|
||||
|
|
Loading…
Reference in New Issue