簡體   English   中英

遍歷表單元素htmlunit

[英]Iterating over form elements htmlunit

您是否知道htmlunit是否支持返回表單元素的表單迭代。 我可以使用getInputByName來獲取特定的元素,如果元素名稱不存在,甚至可以使用值。 但是,例如,如何在列表中獲取特定表單的所有元素。 那有可能還是我需要自己解析表格

非常感謝

從文檔:

XPath is the suggested way for more complex searches, a brief tutorial can be found in W3Schools

@Test
public void xpath() throws Exception {
    final WebClient webClient = new WebClient();
    final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");

    //get list of all divs
    final List<?> divs = page.getByXPath("//div");

    //get div which has a 'name' attribute of 'John'
    final HtmlDivision div = (HtmlDivision) page.getByXPath("//div[@name='John']").get(0);

    webClient.closeAllWindows();
}

因此:不,這是不可能的,您可以使用XPath(用於解析xml(html是xml)的Java庫)來獲得所需的效果。

祝好運 :)

您可以通過多種方式進行迭代,例如選擇行並對其進行迭代

    HtmlTable table = (HtmlTable) filings_page.getByXPath(
            "//table[@class='GDOGFYVLF']").get(0);
    java.util.List<HtmlTableRow> table_rows = table.getRows();
    for (int i = 1; i < table.getRows().size(); i++) {
      //your logic
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM