用Java运行JavaScript

saj*_*jad 2 html javascript java

我有一个javaScript标记:

<!-- Begin ParsTools.com Prayer Times Code -->
<script type="text/javascript" language="javascript" src="http://www2.parstools.com/oghat/oghatwhite.php"></script>
<script language="javascript">
    var CurrentDate= new Date(); 
    var JAT= 1;  
    function pz() {};
    init();
    document.getElementById("cities").selectedIndex=12;
    coord();
    main();
</script>
<!-- End Prayer Times code -->
Run Code Online (Sandbox Code Playgroud)

我想在java中运行此脚本并接收服务器响应的html文档.我怎样才能做到这一点?我还需要解析收到的文档并提取一些特殊标记.

谢谢.

Avi*_*i Y 7

我知道最简单的方法是使用HtmlUnit.

WebClient htmlunit = new WebClient();
HtmlPage page = htmlunit.getPage("http://www.google.com");

//executing the javascript and getting the new page
page = page.executeJavaScript("<JS code here>").getNewPage(); 
Run Code Online (Sandbox Code Playgroud)

更多信息:http://www.aviyehuda.com/2011/05/htmlunit-a-quick-introduction/