可以结合 Jsonp 解析
官方网站:http://htmlunit.sourceforge.net/dependencies.html
下载地址:https://sourceforge.net/projects/htmlunit/files/htmlunit/
WebClient webclient = new WebClient();
webclient.getOptions().setCssEnabled(true);
webclient.getOptions().setJavaScriptEnabled(true);
// 做的第一件事,去拿到这个网页,只需要调用getPage这个方法即可
HtmlPage htmlpage = webclient
.getPage(jobLogHost + "/hp/device/SignIn/Index");
HtmlForm form = (HtmlForm) htmlpage.getElementById("DynamicSignIn");
// 同样道理,获取”百度一下“这个按钮
final HtmlSubmitInput button = (HtmlSubmitInput) form
.getInputsByName("signInOk").get(0);
// 得到搜索框
HtmlPasswordInput passwordInput = form
.getInputByName("PasswordTextBox");
// 设置密码框的value
passwordInput.setValueAttribute("HPRoam123");
// 设置好之后,模拟点击按钮行为。
final HtmlPage nextPage = button.click();
HtmlAnchor a = (HtmlAnchor) nextPage.getElementById("JobLogReport");
HtmlPage jobLog = a.click();
List<Job> jobs = new ArrayList<>();
// 开始获取jobLogId jobLogName
Document document = Jsoup.parse(jobLog.asXml());
依赖
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit-core-js</artifactId>
<version>2.32</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.32</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit-cssparser</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>neko-htmlunit</artifactId>
<version>2.32</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.11.v20180605</version>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
<version>2.7.2</version>
</dependency>
Project Dependencies
compile
The following is a list of compile dependencies for this project. These dependencies are required to compile and run the application:
GroupId | ArtifactId | Version | Type | Licenses |
---|---|---|---|---|
commons-io | commons-io | 2.6 | jar | Apache License, Version 2.0 |
commons-logging | commons-logging | 1.2 | jar | The Apache Software License, Version 2.0 |
commons-net | commons-net | 3.6 | jar | Apache License, Version 2.0 |
net.sourceforge.htmlunit | htmlunit-core-js | 2.32 | jar | Mozilla Public License, Version 2.0 |
net.sourceforge.htmlunit | htmlunit-cssparser | 1.1.0 | jar | Apache License, Version 2.0 |
net.sourceforge.htmlunit | neko-htmlunit | 2.32 | jar | Apache License, Version 2.0 |
org.apache.commons | commons-lang3 | 3.7 | jar | Apache License, Version 2.0 |
org.apache.commons | commons-text | 1.4 | jar | Apache License, Version 2.0 |
org.apache.httpcomponents | httpmime | 4.5.6 | jar | Apache License, Version 2.0 |
org.eclipse.jetty.websocket | websocket-client | 9.4.11.v20180605 | jar | Apache Software License - Version 2.0Eclipse Public License - Version 1.0 |
xalan | xalan | 2.7.2 | jar | The Apache Software License, Version 2.0 |