Giter VIP home page Giter VIP logo

phantomjs's Introduction

install Cases

https://www.npmjs.com/package/phantom

sudo -H npm install phantom --save

(命令行操作) 安装phantom http://phantomjs.org/download.html

vi ~/.bash_profile

alias phantomjs='~/PATH/*/phantomjs'

Use Cases

var phantom = require('phantom');

phantom.create().then(function(ph) {
	ph.createPage().then(function(page) {

		page.property("viewportSize", {'width': 200, 'height': 100});
		page.property("content",'《html》《body》《canvas id="surface" width="200" height="100"》《/canvas》《/body》《/html》');
                
                ⚠️
                需要把"《"转换为"<",把"》"转换为">"
		
		
                // page.content = '';
		
		page.evaluate(function() {
			var c=el = document.getElementById('surface');
			var ctx = el.getContext('2d');
			ctx.font="40px Verdana";
			var gradient=ctx.createLinearGradient(0,0,c.width,0);

			gradient.addColorStop("0","magenta");
			gradient.addColorStop("0.5","blue");
			gradient.addColorStop("1","red");

			//把他赋值给fillStyle

			ctx.fillStyle=gradient;

			ctx.fillText("1234wA",10,80);
		})

		page.render('2.png');

		setTimeout(function(){
			ph.exit();
		},1000);
	
	});
});







var phantom = require('phantom');
phantom.create().then(
	function(ph) {
	  	ph.createPage().then(function(page) {
	  		
	  		page.viewportSize = {
			  	width: 500,
			  	height: 400
			};

			page.open('http://localhost:8888/1.html').then(function(status) {
			// page.open('http://www.baidu.com/').then(function(status) {
				console.log(status);
				page.property('content').then(function(content) {
					// console.log(content);
		        	page.viewportSize = {
					  	width: 200,
					  	height: 100
					};
				  		
				  	page.clipRect = {
						top: 0,
						left: 0,
						width: 200,
						height: 100
					};

					page.paperSize = {
					  	width: '100px',
					  	height: '50in',
					  	margin: {
					    	top: '0px',
					    	left: '0px'
					  	}
					};
		   
					setTimeout(function () {
				       
				        page.render('1.png');
			        	page.close();
			        	ph.exit();

				        console.log('render ok');
				     }, 1000);
		        	
		      	});
		    });
		});
	}
);


PhantomJS - Scriptable Headless WebKit

PhantomJS (phantomjs.org) is a headless WebKit scriptable with JavaScript. The latest stable release is version 2.1.

Note: Please do not create a GitHub pull request without reading the Contribution Guide first. Failure to do so may result in the rejection of the pull request.

Use Cases

  • Headless web testing. Lightning-fast testing without the browser is now possible!
  • Page automation. Access and manipulate web pages with the standard DOM API, or with usual libraries like jQuery.
  • Screen capture. Programmatically capture web contents, including CSS, SVG and Canvas. Build server-side web graphics apps, from a screenshot service to a vector chart rasterizer.
  • Network monitoring. Automate performance analysis, track page loading and export as standard HAR format.

Features

  • Multiplatform, available on major operating systems: Windows, Mac OS X, Linux, and other Unices.
  • Fast and native implementation of web standards: DOM, CSS, JavaScript, Canvas, and SVG. No emulation!
  • Pure headless (no X11) on Linux, ideal for continuous integration systems. Also runs on Amazon EC2, Heroku, and Iron.io.
  • Easy to install: Download, unpack, and start having fun in just 5 minutes.

Questions?

PhantomJS is free software/open source, and is distributed under the BSD license. It contains third-party code, see the included third-party.txt file for the license information on third-party code.

PhantomJS is created and maintained by Ariya Hidayat (Twitter: @ariyahidayat), with the help of many contributors. Follow the official Twitter stream @PhantomJS to get the frequent development updates.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.