Updated examples to use "require('webpage').create()" instead of "new WebPage()".

1.3
Ivan De Marino 2011-09-12 21:17:54 +01:00
parent e960279ff2
commit e0e5535e0e
42 changed files with 43 additions and 42 deletions

View File

@ -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>'

View File

@ -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() {

View File

@ -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'

View File

@ -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) {

View File

@ -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 + ': ?'

View File

@ -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 + ': ?');

View File

@ -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'

View File

@ -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');

View File

@ -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")

View File

@ -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) {

View File

@ -1,4 +1,4 @@
page = new WebPage()
page = require('webpage').create()
if phantom.args.length is 0
console.log 'Usage: loadspeed.js <some URL>'

View File

@ -1,4 +1,4 @@
var page = new WebPage(),
var page = require('webpage').create(),
t, address;
if (phantom.args.length === 0) {

View File

@ -1,4 +1,4 @@
page = new WebPage()
page = require('webpage').create()
address = phantom.args[0]
if phantom.args.length is 0

View File

@ -1,4 +1,4 @@
var page = new WebPage(),
var page = require('webpage').create(),
address = phantom.args[0];
if (phantom.args.length === 0) {

View File

@ -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>'

View File

@ -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>');

View File

@ -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

View File

@ -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);

View File

@ -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,

View File

@ -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) {

View File

@ -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'

View File

@ -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';

View File

@ -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]'

View File

@ -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) {

View File

@ -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'

View File

@ -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";

View File

@ -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) ->

View File

@ -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) {

View File

@ -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) ->

View File

@ -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) {

View File

@ -1,4 +1,4 @@
page = new WebPage()
page = require('webpage').create()
page.viewportSize = { width: 320, height: 480 }

View File

@ -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') {

View File

@ -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")

View File

@ -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")

View File

@ -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 = ->

View File

@ -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 () {

View File

@ -1,4 +1,4 @@
page = new WebPage()
page = require('webpage').create()
console.log 'The default user agent is ' + page.settings.userAgent

View File

@ -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) {

View File

@ -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) ->

View File

@ -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) {

View File

@ -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")

View File

@ -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")