随时随地技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)

canGoBack

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.canGoBack example.

canGoForward

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.canGoForward example.

clipRect

clipRect {object}

This property defines the rectangular area of the web page to be rasterized when page.render is invoked. If no clipping rectangle is set, page.render will process the entire web page.

Examples

var webPage = require('webpage');
var page = webPage.create();page.clipRect = {top: 14,left: 3,width: 400,height: 300
};

Issues

clipRect doesn’t seem to be applied for JPEG render exports, works with PNG though.

指定截图的区域,若没有指定默认整个页面。

content

content {string}

This property stores the content of the web page (main frame), enclosed in an HTML/XML element. Setting the property will effectively reload the web page with the new content.

See also page.plainText to get the content without any HTML tags.

Examples

var webPage = require('webpage');
var page = webPage.create();page.open('http://phantomjs.org', function (status) {var content = page.content;console.log('Content: ' + content);phantom.exit();
});

cookies

Get or set Cookies visible to the current URL (though, for setting, use of page.addCookieis preferred). This array will be pre-populated by any existing Cookie data visible to this URL that is stored in the CookieJar, if any.

Cookies is an array of objects:

{ domain: 'example.com',expires: 'Sat Oct 11 2014 21:44:33 GMT+0200 (CEST)',expiry: 1476128618,httponly: false,name: 'cookieName',path: '/',secure: false,value: cookieValue
}

Examples

var webPage = require('webpage');
var page = webPage.create();page.open('http://phantomjs.org', function (status) {var cookies = page.cookies;console.log('Listing cookies:');for(var i in cookies) {console.log(cookies[i].name + '=' + cookies[i].value);}phantom.exit();
});

customHeaders

customHeaders {object}

Introduced: PhantomJS 1.5

This property specifies additional HTTP request headers that will be sent to the server for every request issued (for pages and resources). The default value is an empty object {}. Headers names and values get encoded in US-ASCII before being sent. Please note that the ‘User-Agent’ should be set using the page.settings, setting the ‘User-Agent’ property in this property will overwrite the value set via page.settings.

Examples

Send two additional headers ‘X-Test’ and ‘DNT’

var webPage = require('webpage');
var page = webPage.create();page.customHeaders = {"X-Test": "foo","DNT": "1"
};

Do you only want these customHeaders passed to the initial page.open request?

Here’s the recommended workaround:

var webPage = require('webpage');
var page = webPage.create();page.customHeaders = {"X-Test": "foo","DNT": "1"
};page.onInitialized = function() {page.customHeaders = {};
};

event

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.event example.

focusedFrameName

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.focusedFrameName example.

content {string}

This property stores the content of the web page (main frame), enclosed in an HTML/XML element. Setting the property will effectively reload the web page with the new content.

See also page.plainText to get the content without any HTML tags.

Examples

var webPage = require('webpage');
var page = webPage.create();page.open('http://phantomjs.org', function (status) {var content = page.content;console.log('Content: ' + content);phantom.exit();
});

frameContent

frameContent {string}

Introduced: PhantomJS 1.7

This property stores the content of the web page’s currently active frame (which may or may not be the main frame), enclosed in an HTML/XML element.

Setting the property will effectively reload the web page with the new content.

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.frameContent example.

frameName

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.frameName example.

framePlainText

framePlainText {string}

Introduced: PhantomJS 1.7

Read-only. This property stores the content of the web page’s currently active frame (which may or may not be the main frame) as plain text — no element tags!

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.framePlainText example.

frameTitle

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.frameTitle example.

frameUrl

frameUrl {string}

Introduced: PhantomJS 1.7

Read-only. This property gets the current URL of the web page’s currently active frame (which may or may not be the main frame).

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.frameUrl example.

framesCount

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.framesCount example.

framesName

Returns array with frames names.

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.framesName example.

libraryPath

libraryPath {string}

This property stores the path which is used by page.injectJs function to resolve the script name.

Initially it is set to the location of the script invoked by PhantomJS.

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.libraryPath example.

navigationLocked

navigationLocked {boolean}

This property defines whether navigation away from the page is permitted or not. If it is set to true, then the page is locked to the current URL. Defaults to false.

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.navigationLocked example.

设置为true后,该页面锁定为当前url。

offlineStoragePath

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.offlineStoragePath example.

ownsPages

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.ownsPages example.

pagesWindowName

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.pagesWindowName example.

pages

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.pages example.

paperSize

paperSize {object}

This property defines the size of the web page when rendered as a PDF.

Values and measurements

paperSize

If no paperSize is defined, the size is defined by the web page.

Supported dimension units are: 'mm''cm''in''px'. No unit means 'px'.

Margin

(Previously known as Border, which can still be used for compatibility purposes)

Margin is optional and defaults to 0. Can be provided as a single dimension or as an object containing one or more of the following properties: 'top''left''bottom''right'. Margin values cannot be negative.

Format

Supported formats are: 'A3''A4''A5''Legal''Letter''Tabloid'.

Orientation

Orientation ('portrait''landscape') is optional and defaults to 'portrait'.

Headers and Footers

A repeating page header and footer can also be added via the header and footer property. These can be provided as an object that contains a height and a contents property. The contents property must be set as a phantom.callback object.

header: {height: "1.2cm",contents: phantom.callback(function(pageNum, numPages) {return "<h1>Header <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>";})
}

Acceptable Objects

The given object should be in either this format:

{width: '200px',height: '300px',margin: '0px'
}

or this format:

{format: 'A4',orientation: 'portrait',margin: '1cm'
}

Examples

var webPage = require('webpage');
var page = webPage.create();page.paperSize = {width: '5in',height: '7in',margin: {top: '50px',left: '20px'}
};

A repeating page header and footer can also be added via this property, as in this example:

var webPage = require('webpage');
var page = webPage.create();page.paperSize = {width: '8.5in',height: '11in',header: {height: "1cm",contents: phantom.callback(function(pageNum, numPages) {return "<h1>Header <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>";})},footer: {height: "1cm",contents: phantom.callback(function(pageNum, numPages) {return "<h1>Footer <span style='float:right'>" + pageNum + " / " + numPages + "</span></h1>";})}
}

plainText

plainText {string}

Read-only. This property stores the content of the web page (main frame) as plain text — no element tags!

See also: page.content which returns the content with element tags.

Examples

var webPage = require('webpage');
var page = webPage.create();page.open('http://phantomjs.org', function (status) {console.log('Stripped down page text:\n' + page.plainText);phantom.exit();
});

scrollPosition

scrollPosition {object}

This property defines the scroll position of the web page.

Examples

var webPage = require('webpage');
var page = webPage.create();page.scrollPosition = {top: 100,left: 0
};

settings

settings {object}

This property stores various settings of the web page:

  • javascriptEnabled defines whether to execute the script in the page or not (defaults to true).
  • loadImages defines whether to load the inlined images or not (defaults to true).
  • localToRemoteUrlAccessEnabled defines whether local resource (e.g. from file) can access remote URLs or not (defaults to false).
  • userAgent defines the user agent sent to server when the web page requests resources.
  • userName sets the user name used for HTTP authentication.
  • password sets the password used for HTTP authentication.
  • XSSAuditingEnabled defines whether load requests should be monitored for cross-site scripting attempts (defaults to false).
  • webSecurityEnabled defines whether web security should be enabled or not (defaults to true).
  • resourceTimeout (in milli-secs) defines the timeout after which any resource requested will stop trying and proceed with other parts of the page. onResourceTimeout callback will be called on timeout.

Note: The settings apply only during the initial call to the page.open function. Subsequent modification of the settings object will not have any impact.

Examples

var webPage = require('webpage');
var page = webPage.create();
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';

title

Examples

page.open('http://phantomjs.org', function (status) {console.log(page.title); // get page Titlephantom.exit();
});

url

url {string}

Introduced: PhantomJS 1.7 Read-only. This property gets the current URL of the web page (main frame).

Examples

var webPage = require('webpage');
var page = webPage.create();page.open('http://phantomjs.org', function (status) {var url = page.url;console.log('URL: ' + url);phantom.exit();
});

viewportSize

viewportSize {object}

This property sets the size of the viewport for the layout process. It is useful to set the preferred initial size before loading the page, e.g. to choose between 'landscape' vs 'portrait'.

Because PhantomJS is headless (nothing is shown), viewportSize effectively simulates the size of the window like in a traditional browser.

Examples

var webPage = require('webpage');
var page = webPage.create();page.viewportSize = {width: 480,height: 800
};

You must include height for this to work.

var page = require('webpage').create(),address, output, size;
var system = require('system');  var arg_count = system.args.length - 1;
if (arg_count < 4 || arg_count > 5) {console.log('Usage: viewport.js URL filename sizeX sizeY');phantom.exit();
} else {address = system.args[1];output = system.args[2];sizeX = system.args[3];sizeY = system.args[4];page.viewportSize = { width: sizeX, height: sizeY };page.open(address, function (status) {if (status !== 'success') {console.log('Unable to load the address!');} else {window.setTimeout(function () {page.render(output);phantom.exit();}, 200);}});
}

Usage: viewport.js URL filename sizeX sizeY

windowName

Examples

var webPage = require('webpage');
var page = webPage.create();
// @TODO: Finish page.windowName example.

zoomFactor

zoomFactor {number}

This property specifies the scaling factor for the page.render and page.renderBase64functions.

The default is 1, i.e. 100% zoom.

Examples

Create a thumbnail preview with 25% zoom

var webPage = require('webpage');
var page = webPage.create();page.zoomFactor = 0.25;
page.render('capture.png');

phontomjs webpage模块属性相关推荐

  1. phontomjs webPage模块方法

    随时随地技术实战干货,获取项目源码.学习资料,请关注源代码社区公众号(ydmsq666) addCookie addCookie(Cookie) {boolean} Introduced: Phant ...

  2. ABB机器人的程序结构与模块属性

    ABB机器人的程序结构 在ABB机器人中,机器人所运行的程序被称为RAPID, RAPID下面又划分了Task(任务),任务下面又划分了module(模块),模块是机器人的程序与数据的载体,模块又分为 ...

  3. abb机器人指令手册_ABB机器人的程序结构与模块属性

    ABB机器人的程序结构与模块属性ABB机器人的程序结构在ABB机器人中,机器人所运行的程序被称为RAPID, RAPID下面又划分了Task(任务),任务下面又划分了module(模块),模块是机器人 ...

  4. python的类与模块_Python类与模块属性

    what is a good use case for class attributes 案例0.类方法只是类属性.这不仅仅是一个技术上的相似性--您可以在运行时通过为类方法分配可调用项来访问和修改它 ...

  5. Python正则表达式: 元字符/转义/分组/匹配原则/re模块属性方法大全

    正则表达式 动机 文本处理已经成为计算机常见工作之一 对文本内容的搜索,定位,提取是逻辑比较复杂的工作 为了快速方便的解决上述问题,产生了正则表达式技术 简介 定义 即文本的高级匹配模式,提供搜索,替 ...

  6. matlab_simulink笔记01——模块属性的设置以及模块参数的设置

    这里以延迟模块为例

  7. Unity技术手册 - 粒子基础主模块属性-下

    往期文章分享 点击跳转=><导航贴>- Unity手册,系统实战学习 点击跳转=><导航贴>- Android手册,重温移动开发 本文约3.3千字,新手阅读需要11 ...

  8. Unity技术手册 - 粒子基础主模块属性-中

    往期文章分享 点击跳转=><导航贴>- Unity手册,系统实战学习 点击跳转=><导航贴>- Android手册,重温移动开发 本文约3.3千字,新手阅读需要11 ...

  9. Unity技术手册 - 粒子基础主模块属性-上

    往期文章分享 点击跳转=><导航贴>- Unity手册,系统实战学习 点击跳转=><导航贴>- Android手册,重温移动开发 本文约3.3千字,新手阅读需要11 ...

最新文章

  1. Java项目:医院管理系统(java+Springboot+Maven+Mybatis+Vue+Mysql)
  2. 用Uber的方式管理机器学习模型
  3. linux .desktop权限,如何在Ubuntu Xenial Xerus 16.04 Linux Desktop上以root用户身份登录
  4. Mybatis下collections使用pageHelper进行分页
  5. 可视化实战!Python+BI,手把手教你做炫酷的NBA可视化分析
  6. HAproxy开启日志记录
  7. 对团队成员公开感谢博客
  8. 实时查询(otoci)
  9. JAVASCRIPT视频教程推荐==李炎恢JavaScript教程 第一季
  10. word转html制作操作手册,Word文档转换为HTML帮助文档操作手册范本.pdf
  11. vijos 1540 月亮之眼 并查集
  12. RSS简述 及 Java构造RSS接口
  13. win10系统怎么把python卸载干净_Win10系统卸载python软件失败提示0x
  14. python 常用的内置模块
  15. 黑胶音乐和CD音乐有什么区别?
  16. 设计模式之美总结(设计原则篇)
  17. JVM 判断对象已死,实践验证GC回收
  18. SecureCRT中文乱码解决(汇总)
  19. python趣味案例编程 Pdf,小小的python编程故事
  20. ARPANET的设计思想 (分组交换)

热门文章

  1. 《被讨厌的勇气》节选:直面人生,课题分离
  2. 全球与中国静注人免疫球蛋白市场深度研究分析报告
  3. 软件测试现在想拿到20k的高薪offer,到底是不是痴人说梦
  4. ppt软件有哪些,推荐一下
  5. Bringing Old Photos Back to Life模型代码分析1(数据载入部分)
  6. 算法竞赛入门10.2计数与概率基础例题代码
  7. js动画与html动画效果,九种原生js动画效果
  8. IM品头论足:内存占用谁最省?
  9. 数字图像处理中imfilter函数卷积算法代码(matlab)
  10. Authentication method ‘caching_sha2_password‘ not supported by any of the available plugins.