开发者

is it possible to load a HtmlPage from a string?

I have stored a webpage's HTML in the database.

I want to take advantage of HtmlUnit's ability to find/reference DOM elements.

Is it possible to load the HtmlPage object fr开发者_运维百科om a string (via a database column)?


StringWebResponse may help.

Edit: example:

    URL url = new URL("http://www.example.com");
    StringWebResponse response = new StringWebResponse("<html><head><title>Test</title></head><body></body></html>", url);
    HtmlPage page = HTMLParser.parseHtml(response, new TopLevelWindow("top", new WebClient()));
    System.out.println(page.getTitleText());


I assume you're using HtmlParser.parseHtml to create the HtmlPage object and just need a WebResponse to pass to it?

If so, StringWebResponse will wrap your string so you can pass it directly to parseHtml.


uhhmm well yes.

You just need to serve it ( if you're using java you can use Tomcat for that ) and point your test to the served page.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜