import java.util.List;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
public class Main {
public static void main(String args[]) {
new Main();
}
private WebClient webClient;
private boolean isSelected;
public Main() {
webClient = new WebClient();
isSelected = false;
try {
rightPanel();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void rightPanel() throws Exception {
// **************log in***********************
// Get the first page
HtmlPage page1 = webClient
.getPage("http://jwxt.sdu.edu.cn:7777/zhxt_bks/xk_login.html");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
// final HtmlForm form = page1.getFormByName("");
List<HtmlForm> forms = page1.getForms();
HtmlForm form = null;
for (int i = 0; i < forms.size(); i++) {
form = forms.get(i);
// System.out.println(form);
}
HtmlSubmitInput button = form.getInputByName("");
System.out.println(button);
HtmlTextInput nameField = form.getInputByName("stuid");
System.out.println(nameField);
HtmlPasswordInput passField = form.getInputByName("pwd");
System.out.println(passField);
// Change the value of the text field
nameField.setValueAttribute("200805270076");
passField.setValueAttribute("*********s");
// Now submit the form by clicking the button and get back the second
// page.
HtmlPage page2 = button.click();
System.out.println(page2.asXml());
HtmlPage page3 = webClient
.getPage("http://jwxt.sdu.edu.cn:7777/pls/wwwbks/xk.CourseInput");
System.out.println(page3.asXml());
// *****************select begin*******************
System.out.println("*******************************");
forms = page3.getForms();
for (int i = 0; i < forms.size(); i++) {
form = forms.get(i);
System.out.println(form);
}
button = form.getInputByName("");
System.out.println(button);
HtmlTextInput numField = form.getInputByName("p_qxrxk");
System.out.println(numField);
HtmlTextInput noField = form.getInputByName("p_qxrxk_kxh");
System.out.println(noField);
// select embedded system teached by Jia Zhiping.
HtmlPage page4;
while (!isSelected) {
numField.setValueAttribute("13105000");
noField.setValueAttribute("100");
page4 = button.click();
System.out.println(page4.asXml());
Thread.sleep(1000);
}
webClient.closeAllWindows();
}
class refreshThread extends Thread {
public refreshThread(String num) {
}
}
}