當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript webpage.create函數代碼示例

本文整理匯總了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;
開發者ID:AbraaoAlves,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:slimerjs-tests.ts

示例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
開發者ID:chen-framework,項目名稱:crawler,代碼行數:31,代碼來源:extractor.ts

示例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();
  }
});
開發者ID:villers,項目名稱:OnlineMarkdownEditorApi,代碼行數:25,代碼來源:render.ts


注:本文中的webpage.create函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。