Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to load a HtmlPage from a string?

Tags:

java

htmlunit

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 from a string (via a database column)?

like image 298
mrblah Avatar asked Dec 18 '22 03:12

mrblah


1 Answers

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());
like image 78
Mirko N. Avatar answered Jan 04 '23 06:01

Mirko N.