【Jsoup示例(打印表单参数)】在此示例中, 我们将打印表单参数, 例如参数名称和参数值。为此, 我们调用Document类的getElementById()方法和Element类的getElementsByTag()方法。
register.html
<
!DOCTYPE html>
<
html>
<
head>
<
meta charset="utf-8">
<
title>
Register Please<
/title>
<
/head>
<
body>
<
form id="registerform" action="register.jsp" method="post">
Name:<
input type="text" name="name" value="http://www.srcmini.com/sonoo"/>
<
br/>
Password:<
input type="password" name="password" value="http://www.srcmini.com/sj"/>
<
br/>
Email:<
input type="email" name="email" value="http://www.srcmini.com/sonoojaiswal1987@gmail.com"/>
<
br/>
<
input name="submitbutton" type="submit" value="http://www.srcmini.com/register"/>
<
/form>
<
/body>
<
/html>
JsoupPrintFormParameters.java
import java.io.File;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class JsoupPrintFormParameters {
public static void main(String[] args) throws IOException {
Document doc = Jsoup.parse(new File("e:\\register.html"), "utf-8");
Element loginform = doc.getElementById("registerform");
Elements inputElements = loginform.getElementsByTag("input");
for (Element inputElement : inputElements) {
String key = inputElement.attr("name");
String value = http://www.srcmini.com/inputElement.attr("value");
System.out.println("Param name: "+key+" \nParam value: "+value);
}
}
}
输出:
Param name: name
Param value: sonoo
Param name: password
Param value: sj
Param name: email
Param value: sonoojaiswal1987@gmail.com
Param name: submitbutton
Param value: register
推荐阅读
- Jsoup示例(打印URL的图像)
- Jsoup API
- 安装Jsoup
- 如何修复佳能打印机错误代码5100(解决办法指南)
- 什么是Eudcedit.exe(错误以及如何修复它?)
- 什么是hdwwiz.exe(用途以及如何修复错误?)
- Eventvwr.exe指南(它是什么、用途以及如何启动它())
- 如何在Windows 10上修复Audacity错误代码9999()
- 如何在Windows 10上修复LastPass错误代码1603()