我编写了以下简单的代码来自动将数据输入网站。但是,我收到以下错误:
Exception in thread "main" java.net.ConnectException: Connection refused: connect
我正在使用 NetBeans。
代码:
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Scanner;
import com.gargoylesoftware.htmlunit.Page;
import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import com.gargoylesoftware.htmlunit.html.*;
public class ts {
public static void main(String[] args) throws IOException{
final WebClient webClient = new WebClient();
HtmlPage page = (HtmlPage)webClient.getPage( new URL("http://rise4fun.com/QuickCode") );
final HtmlForm form = (HtmlForm)page.getFormsByName("form1").get(0);
final HtmlInput inp = form.getInputByName("SourceBox");
inp.setValueAttribute("24.9.2011 | 24 Sep 2011\n8/15/2010");
HtmlSubmitInput sub=(HtmlSubmitInput) page.getHtmlElementById("AskButton");
page = (HtmlPage)sub.submit();
final String pageAsText = page.asText();
HtmlElement out=page.getHtmlElementById("OutputBox");
System.out.println(out.asText());
}
}