【发布时间】:2018-11-17 08:19:18
【问题描述】:
这是我的代码。我想访问一个网站并比较我的数据。我希望java将数据放入字段并自动点击计算底部并将答案返回给java。
import com.gargoylesoftware.htmlunit.WebClient;
public class MyWebServiceAccess {
public static void main(String[] args) throws Exception
{
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("https://www.socscistatistics.com/tests/signedranks/Default2.aspx");
// Inputs
HtmlTextInput treatment1 = (HtmlTextInput) page.getElementById("ctl00_MainContent_TextBox1");
HtmlTextInput treatment2 = (HtmlTextInput) page.getElementById("ctl00_MainContent_TextBox2");
// Significance Level:
HtmlRadioButtonInput s1= (HtmlRadioButtonInput) page.getElementById("ctl00_MainContent_RadioButtonList1_0");
HtmlRadioButtonInput s2= (HtmlRadioButtonInput) page.getElementById("ctl00_MainContent_RadioButtonList1_1");
// 1 or 2-tailed hypothesis?:
HtmlRadioButtonInput t1= (HtmlRadioButtonInput) page.getElementById("ctl00_MainContent_RadioButtonList2_0");
HtmlRadioButtonInput t2= (HtmlRadioButtonInput) page.getElementById("ctl00_MainContent_RadioButtonList2_1");
// Calculate
HtmlSubmitInput Calculate= (HtmlSubmitInput) page.getElementById("ctl00_MainContent_Button2");
// Result Span
HtmlSpan result = (HtmlSpan) page.getElementById("ctl00_MainContent_Label9");
// Fill in Inputs
treatment1.setValueAttribute("");
treatment2.setValueAttribute("");
s1.setChecked(true);
s2.setChecked(false);
t1.setChecked(true);
t2.setChecked(false);
Calculate.click();
// Printing the Output
System.out.println(result.asText());
webClient.closeAllWindows();
}
}
【问题讨论】:
-
您的问题是什么?不要告诉我这是“怎么做?”因为那是一种广泛的方式。
-
我的问题是我无法连接到 HTML 页面并做我想做的事。我正在寻找我的代码问题而不是实现它的方式。
-
用您的问题更新您的问题,然后包括任何错误以及给您带来麻烦的代码部分。