is it possible to load a HtmlPage from a string?

家住魔仙堡 提交于 2019-12-04 10:00:41

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!