mirror of https://github.com/vitalif/phantomjs
rasterize.js: Port to WebPage object.
parent
5da05055cc
commit
f84bef4b38
|
@ -1,13 +1,12 @@
|
||||||
// Find pizza in New York using Google Local
|
// Find pizza in New York using Google Local
|
||||||
|
|
||||||
var page = new WebPage(),
|
var page = new WebPage();
|
||||||
results = [];
|
|
||||||
|
|
||||||
page.open('http://www.google.com/m/local?site=local&q=pizza+in+new+york', function (status) {
|
page.open('http://www.google.com/m/local?site=local&q=pizza+in+new+york', function (status) {
|
||||||
if (status !== 'success') {
|
if (status !== 'success') {
|
||||||
console.log('Unable to access network');
|
console.log('Unable to access network');
|
||||||
} else {
|
} else {
|
||||||
results = page.evaluate(function() {
|
var results = page.evaluate(function() {
|
||||||
var list = document.querySelectorAll('div.bf'), pizza = [], i;
|
var list = document.querySelectorAll('div.bf'), pizza = [], i;
|
||||||
for (i = 0; i < list.length; i++) {
|
for (i = 0; i < list.length; i++) {
|
||||||
pizza.push(list[i].innerText);
|
pizza.push(list[i].innerText);
|
||||||
|
|
|
@ -1,22 +1,27 @@
|
||||||
if (phantom.state.length === 0) {
|
var page = new WebPage(),
|
||||||
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
address, output, size;
|
||||||
|
|
||||||
|
if (phantom.args.length < 2 || phantom.args.length > 3) {
|
||||||
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
|
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat]');
|
||||||
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
} else {
|
} else {
|
||||||
var address = phantom.args[0];
|
address = phantom.args[0];
|
||||||
phantom.state = 'rasterize';
|
output = phantom.args[1];
|
||||||
phantom.viewportSize = { width: 600, height: 600 };
|
page.viewportSize = { width: 600, height: 600 };
|
||||||
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
|
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
|
||||||
var size = phantom.args[2].split('*');
|
size = phantom.args[2].split('*');
|
||||||
phantom.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' }
|
phantom.paperSize = size.length === 2 ? { width: size[0], height: size[1], border: '0px' }
|
||||||
: { format: phantom.args[2], orientation: 'portrait', border: '1cm' };
|
: { format: phantom.args[2], orientation: 'portrait', border: '1cm' };
|
||||||
}
|
}
|
||||||
phantom.open(address);
|
page.open(address, function (status) {
|
||||||
}
|
if (status !== 'success') {
|
||||||
} else {
|
console.log('Unable to load the address!');
|
||||||
var output = phantom.args[1];
|
} else {
|
||||||
phantom.sleep(200);
|
window.setTimeout(function () {
|
||||||
phantom.render(output);
|
page.render(output);
|
||||||
phantom.exit();
|
phantom.exit();
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue