如何将html源代码打印到phantomjs控制台 [英] How to print html source to console with phantomjs
本文介绍了如何将html源代码打印到phantomjs控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚在我的机器上下载并安装了phantomjs。我将以下脚本复制并粘贴到名为hello.js的文件中:
I just downloaed and installed phantomjs on my machine. I copy and pasted the following script into a file called hello.js:
var page = require('webpage').create();
var url = 'https://www.google.com'
page.onLoadStarted = function () {
console.log('Start loading...');
};
page.onLoadFinished = function (status) {
console.log('Loading finished.');
phantom.exit();
};
page.open(url);
我想将完整的html源代码(在本例中是从google页面)打印到文件或控制台。我怎么做到这一点?
I'd like to print the complete html source (in this case from the google page) to a file or to the console. How do I do this?
推荐答案
花费一些时间阅读文档,应该很明显。 b
$ b
Spent some time to read the documentation, it should be obvious afterwards.
var page = require('webpage').create();
page.open('http://google.com', function () {
console.log(page.content);
phantom.exit();
});
这篇关于如何将html源代码打印到phantomjs控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文