在java程序中执行phantomjs脚本
Execute phantomjs script in java program
我有一个问题:我必须在java程序中执行一个phantomjs脚本,但我不能。这是脚本的代码:
var page = require('webpage').create();
page.open('http://stackoverflow.com',function(status){
if(status !== 'success'){
console.log('Open failed');
}else{
console.log(page.evaluate(function(){
return document.documentElement.outerHTML;
}));
}
phantom.exit();
});
在实践中,我想执行网页的javascript,然后获取html结果。我尝试使用此链接中的代码从javascript,JSP或Java运行Phantomjs,但是我的程序在此行被阻止
int exitStatus = process.waitFor();
我该怎么做才能解决这个问题?
谢谢
您可以使用运行时类来执行终端命令。我能够使用以下程序生成我想要的输出。
Runtime rt = Runtime.getRuntime();
try{
Process pr = rt.exec("pathToPhantomHome/phantomjs "+ " pathToJSfile");
BufferedInputStream bis = new BufferedInputStream(pr.getInputStream());
bis.close();
}catch(Exception ex){
ex.printStackTrace();
}
相关文章:
- 当尝试登录instagram时,带有Selenium的Phantomjs不处理iframe Java脚本
- Phantomjs 脚本在 JSON 对象解析后停止执行
- 如何在 PhantomJS 中获取当前脚本名称
- 在java程序中执行phantomjs脚本
- 将脚本添加到 DOM 后,JQuery 不能在 Watir 中使用 PhantomJS
- 带有外部脚本的PhantomJS节点
- 每x分钟运行一次phantomjs脚本
- 用PHP中的PhantomJS截屏,并将参数传递给脚本
- 在phantomjs交互(REPL)模式下执行脚本
- 在symfony中放置phantomjs脚本的位置
- PhantomJS页面转储脚本问题
- 点击按钮时运行PhantomJS脚本
- 如何远程获取在heroku上运行的phantomjs脚本的答案
- 在PhantomJS中,为什么jQuery调用会导致脚本挂起?
- 为什么我的phantomjs脚本输出没有截图(命令行args版本)
- 暂停和恢复CasperJS, PhantomJS脚本
- 我如何将这个PhantomJS脚本更改为NodeJS进行web抓取
- 使用require()将JS脚本转换为服务器端/PhantomJS
- 使用Selenium Driver+PhantomJS注入JavaScript脚本,并在Python中正确处理重定向
- 在PhantomJS脚本中等待函数执行结束