htmlファイルに含まれているテーブルにアクセスしたいのですが。これが私のコードです:
import java.io.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.WebClient;
public class test {
public static void main(String[] args) throws Exception {
WebClient client = new WebClient();
HtmlPage currentPage = client.getPage("http://www.mysite.com");
client.waitForBackgroundJavaScript(10000);
final HtmlDivision div = (HtmlDivision) currentPage.getByXPath("//div[@id='table-matches-time']");
String textSource = div.toString();
//String textSource = currentPage.asXml();
FileWriter fstream = new FileWriter("index.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(textSource);
out.close();
client.closeAllWindows();
}
}
テーブルは次の形式です。
<div id="table-matches-time" class="">
<table class=" table-main">
しかし、私はこのエラーを受け取ります:
Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlDivision
at test.main(test.java:20)
この表を読むにはどうすればよいですか?