我想使用Pattern
&从网页中检索一些值Matcher
<form name="loginForm" id="loginForm" method="post" onsubmit="ScrollUp(60);return validateLoginForm();"
enctype="multipart/form-data" action="/login.php">
<input type="hidden" name="Rpidci" value="">
<div class="last_box">
<div class="second_box_heading_panel">
<h1>Existing users -
<span> Login here</span>
</h1>
</div>
<div class="second_box_form_panel">
<div class="error-msg">
</div>
<div class="name_form_panel">
<div class="name">User Name
</div>
<div class="name_text_field">
<input name="sHZnGSgdzmIJoKWOCHmYez" type="text" class="existing_user round_four" id="sHZnGSgdzmIJoKWOCHmYez" maxlength="10" value=""/>
</div>
</div>
<div class="name_form_panel">
<div class="name">Password
</div>
<div class="name_text_field"><input name="AWrPDfe" type="password" class="existing_user round_four" id="AWrPDfe" maxlength = "20"
value=""/>
</div>
</div>
<div class="login_btn"><a href="javascript:void(0);" onclick="javascript:ScrollUp(70);return validateLoginForm();"><img src="images/login_btn.png" title="login here" /></a></div>
</div>
</div>
<div class="name_form_panel"></div>
</div>
</div>
</form>
我想检索这两个字段的值
<input name="sHZnGSgdzmIJoKWOCHmYez" type="text" class="existing_user round_four" id="sHZnGSgdzmIJoKWOCHmYez" maxlength="10" value=""/>
&
<input name="AWrPDfe" type="password" class="existing_user round_four" id="AWrPDfe" maxlength = "20" value=""/>
我尝试了几次,但未能获得输出。请帮忙。
编辑:
我尝试的代码如下:(与我最初写的不一样,因为我很沮丧并且把它搞砸了)
Matcher matcher = Pattern.compile("<form name=\"loginForm\" .+ method=\"post\" .+ action=\"/login.php\">\\s*<input[^>]+>\\s*<input[^>]+>\\s*").matcher(loginResp);
String[] strArr = matcher.group(0).split("<input");
String str1 = "";
String str2 = "";
String str3 = "";
String str4 = "";
Pattern localPattern = Pattern.compile(" name=\"([^\\s]+)\" type=\"text\" id=\"([^\\s]+)\" value=\"([^\\s]+)\" />");
Matcher localMatcher2 = localPattern.matcher(strArr[3]);
if (localMatcher2.find()) {
str1 = localMatcher2.group(1);
echo("STR1 " + str1);
str2 = localMatcher2.group(3);
echo("STR2 " + str2);
}