我正在努力学习我在Htmlunit周围的方式,我正在研究这个小屏幕碎片,应该从某个网站获得酒店房间的价格。但是,最后一次按钮单击似乎不起作用。它不会加载新页面但保留旧页面。我认为这可能是一个javascript问题。
public static void scrapper() throws Exception {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
HtmlPage page = webClient.getPage("https://gc.synxis.com/rez.aspx?Hotel=51174&Chain=12113&locale=nl-NL");
//click first button
HtmlElement theElement1 = (HtmlElement) page.getElementById("V0_C3_CBtn");
page = theElement1.click();
System.out.println("Current page: Hampshire Hotels");
//click the second button. Popup will appear.
HtmlElement theElement2 = (HtmlElement) page.getElementById("V1_C2_ProductDetailRepeater_ctl02_SelectProductButton");
page = theElement2.click();
//click the third button on popup.
HtmlElement theElement3 = (HtmlElement) page.getElementById("PackageSelect_ContinueButtonBottom");
System.out.println("pressing last button");
page = theElement3.click();
System.out.println("Current page: Hampshire Hotels2");
//getting the price.
List<?> price = page.getByXPath("//html[@id='RezHtml']/body/form[@id='XbeForm']/div[@id='XbeView']/div/div[2]/div[@id='XbeViewPanel']/div/div[1]/div[1]/div[@id='V28_C4_PropertyNameDiv']/span[@id='V28_C4_PropertyNameLabel']/text()");
System.out.println("price: " + price);
//saves the web page
String htmlContent = page.asXml();
File htmlFile = new File("C:/index.html");
PrintWriter pw = new PrintWriter(htmlFile);
pw.print(htmlContent);
pw.close();
webClient.closeAllWindows();
}