开发者

Get a web page in Java Class

I currently use the开发者_如何学C htmlunit library to get a web page with all the javascript and jsp loaded. htmlunit doesn't seem very poweful -- what alternatives exist?


HtmlUnit is quite powerful if you have the time to learn it. If the time it takes to learn HtmlUnit is your obstacle (as it was mine), JWebUnit might be a good option for you. It's based on HtmlUnit, but it's much easier to use and learn. It's been about a year since I used it, but it was exactly what I needed when I was still a Java newbie.


I've used Apache HTTP client and was pleased.

Here is a link.


HTMLUnit is afaik the only option for what people call "headless browser", and as I get it, this is the functionality you need. Just you to know (from my experience): sometimes result from htmlunit, and browsers are a bit different; but it depends on what you need (or how you use that result). Few times I got wrong dynamic element position, and there are two options:

  1. I could change javascript, to get the same result for all major browsers and htmlunit
  2. I had to add some css style, and javascript code, whcih does not influence page view I get in browser, but helps htmlunit to fix layout in right way.

And actually it is quite logical - no browser uses htmlunit as rendering engine :) And that's was the only problem with this library so far.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜