本文整理匯總了TypeScript中webpage.create函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript create函數的具體用法?TypeScript create怎麽用?TypeScript create使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了create函數的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: require
const webpageMod = require('webpage'); // tslint:disable-line no-var-requires
const webserverMod = require('webserver').create(); // tslint:disable-line no-var-requires
let page = webpageMod.create();
let vUrl = 'https://www.w3c.org';
function testWebserver() {
webserverMod.close();
webserverMod.listen(1234);
webserverMod.registerFile("urlPath", "filePath");
webserverMod.registerDirectory("urlPath", "dirPath");
}
let vUserAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 (KHTML, like Gecko) Version/10.0.3 Safari/602.4.8';
page.settings.userAgent = vUserAgent;
page.onConsoleMessage = (vMsg) => {
};
page.onAlert = (vMsg) => {
};
page.onLoadStarted = () => {
};
page.captureContent = [/json/];
page.onResourceReceived = (oResponse) => {
oResponse.id;
oResponse.bodySize;
oResponse.body;
示例2: require
const system: System = require('system');
const url = system.args[1];
if (!url) {
console.log('Usage: phantomjs extractor.js "<some URL>" "<JSON config>"');
phantom.exit(1);
}
import { create as createWebPage } from 'webpage';
const page = createWebPage();
/**
* This callback is invoked when there is a JavaScript console message on the web page
* @param {string} message
* @param {number} lineNum
* @param {string} sourceId
*/
page.onConsoleMessage = function (message, lineNum, sourceId) {
console.log('CONSOLE: ' + message + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
/**
* This callback is invoked when the page requests a resource
* @param {requestData} request
* @param {networkRequest} network
*/
page.onResourceRequested = function (request, network) {
// other unnecessary links
if (request.url.indexOf('facebook.com') !== -1
|| request.url.indexOf('twitter.com') !== -1
示例3: require
declare var phantom: any;
var webpage = require('webpage');
var system = require('system');
var page = webpage.create();
var address: string;
var output: string;
address = system.args[1];
output = system.args[2];
page.viewportSize = { width: 1024, height: 768 };
page.paperSize = { format: 'A4', orientation: 'portrait', margin: '1cm', border: '0px' };
page.open(address, function (status: string): void {
if (status !== 'success') {
console.log('Unable to load the address!');
console.log(status);
console.log(address);
console.log(output);
phantom.exit();
} else {
page.render(output);
phantom.exit();
}
});