How to get a HTML page using HtmlUnit

前端 未结 1 1436
借酒劲吻你
借酒劲吻你 2021-01-03 07:45

I know you may think this question is stupid, but I need to use HtmlUnit. However, it returns a page either as XML or as text.

I don\'t how to get the pure HTML (the

1条回答
  •  执笔经年
    2021-01-03 08:11

    You can use the following piece of code to achieve your goal:

    WebClient webClient = new WebClient();
    Page page = webClient.getPage("http://example.com");
    WebResponse response = page.getWebResponse();
    String content = response.getContentAsString();
    

    See javadocs of the WebResponse.html#getContentAsString() method.

    0 讨论(0)
提交回复
热议问题