0
HtmlUnit을 사용하여 검색 사이트 여행 티켓을 시뮬레이션하려고합니다. 목표는 페이지에서 검색 결과를 얻는 것입니다.htmlunit을 사용하여 결과 페이지 검색
public class TestHtmlUnit {
public static void main(String[] args) throws Exception {
// Create and initialize WebClient object
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_10);
webClient.setThrowExceptionOnScriptError(false);
webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws IOException {
System.out.println("handleRefresh");
}
});
// visit Yahoo Mail login page and get the Form object
HtmlPage page = (HtmlPage) webClient.getPage("http://www.voyages-sncf.com/");
HtmlForm form = page.getFormByName("TrainTypeForm");
// Enter login and passwd of
form.getInputByName("origin_city").setValueAttribute("paris");
form.getInputByName("destination_city").setValueAttribute("marseille");
form.getInputByName("outward_date").setValueAttribute("28/03/2013");
// Click "Sign In" button/link
page = (HtmlPage) form.getInputByValue("Rechercher").click();
// Print the newMessageCount to screen
//System.out.println("newMessageCount = " + newMessageCount);
// System.out.println(page.asHTML());
System.out.println(page.asText());
}
}