2014-09-12 2 views
1

htmlunit이 양식 요소가 반환되는 양식 반복을 지원하는지 알고 있습니까? getInputByName을 사용하거나 특정 요소 이름이없는 경우 값을 사용하여 특정 요소를 가져올 수 있습니다. 하지만 특정 양식의 모든 요소를 ​​목록에서 가져 오는 것은 어떻습니까? 이 수 또는 내가 형태로 자신폼 요소 반복 htmlunit

많은 감사 워드 프로세서

답변

0

구문 분석 할 필요가 : SO

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(); 
} 

을 : 아니, possiable없는 그, 당신이 XPath를 사용할 수 있습니다 (A 자바 라이브러리 xml (html은 xml)을 구문 분석하기 위해) 원하는 효과를 얻으십시오.

행운을 빕니다 :)

0

당신은 예

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 
    } 
를 행을 선택하고 그들에 반복을위한 여러 가지 방법으로 반복 할 수