使用 Java 读取 HTML+JavaScript [英] Reading HTML+JavaScript using Java
问题描述
我可以通过 http 读取 HTML 内容(例如,http://www.foo.com)使用 Java(带有 URL 和 BufferedReader 类).但是,其中一些包含 JavaScript.我当前的应用无法处理 JavaScript.
I can read the HTML contents via http (for example, http://www.foo.com) using Java (with URL and BufferedReader classes). However, a couple of them contain JavaScript. My current app cannot process JavaScript.
使用 Java 使用 JavaScript 读取 HTML 内容的最佳方式是什么?
What's the best way to read HTML content with JavaScript using Java?
如果更容易,我愿意使用其他语言.
I am open using other languages if it is easier.
预先感谢您的帮助.
更新 - 说明:
一些 HTML 内容是使用 JavaScript 动态生成的.在浏览器上查看时,我可以看到结果(JavaScript 处理后的纯 HTML).
A couple HTML contents are generated dynamically using JavaScript. I can see the result (in pure HTML after the JavaScript processing) when viewing them on a browser.
另一方面,当我的 Java 应用检索 HTML 内容时,它说我的应用中没有 JavaScript.
On the other hand, when my Java app retrieves the HTML contents, it says that there is no JavaScript on my app.
理想情况下,我希望能够使用我的 Java 应用程序获得与浏览器相同的结果.
Ideally, I want to be able to get the same result as on the browser using my Java app.
感谢大家的回复.
推荐答案
HtmlUnit 具有良好的 JavaScript 支持,它应该(几乎)将 HTML 解析为 Web 浏览器.
HtmlUnit has good JavaScript support and it should (almost) parse the HTML as a web browser.
这篇关于使用 Java 读取 HTML+JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!