How to programmatically access web page in java

后端 未结 5 1430
无人及你
无人及你 2021-01-30 18:17

There is a web page from which I want to retrieve a certain string. In order to do so, I need to login, click some buttons, fill a text box, click another button - and then the

5条回答
  •  别那么骄傲
    2021-01-30 18:43

    The super simple way to do this is using HtmlUnit here:

    http://htmlunit.sourceforge.net/

    and what you want to do can be as simple as:

    @Test
    public void homePage() throws Exception {
        final WebClient webClient = new WebClient();
        final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
        assertEquals("HtmlUnit - Welcome to HtmlUnit", page.getTitleText());
    }
    

提交回复
热议问题