开发者

is it possible to load a HtmlPage from a string?

开发者 https://www.devze.com 2022-12-15 20:30 出处:网络
I have stored a webpage\'s HTML in the database. I want to take advantage of HtmlUnit\'s ability to find/reference DOM elements.

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

精彩评论

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

关注公众号