データを取り、タグなしで整理したい。こんな感じです
<table class="SpecTable">
<col width="40%" />
<col width="60%" />
<tr>
<td class="LightRowHead">Optical Zoom:</td>
<td class="LightRow">15x</td>
</tr>
<tr>
<td class="DarkRowHead">Digital Zoom:</td>
<td class="DarkRow">6x</td>
</tr>
<tr>
<td class="LightRowHead">Battery Type:</td>
<td class="LightRow">Alkaline</td>
</tr>
<tr>
<td class="DarkRowHead">Resolution Megapixels:</td>
<td class="DarkRow">14 MP</td>
</tr>
</table>
そして、すべての情報の文字列を抽出して、これだけでプレーンテキスト ファイルに保存できるようにしたいと考えています。
光学ズーム: 15 倍 デジタル ズーム: 6 倍 バッテリーの種類: アルカリ 解像度 メガピクセル: 14 MP
public static void main(String[] args) {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);
String Url = "http://www.walmart.com/ip/Generic-14-MP-X400-BK/19863348";
driver.get(Url);
List<WebElement> resultsDiv = driver.findElements(By.xpath("//table[contains (@class,'SpecTable')//td"));
System.out.println(resultsDiv.size());
for (int i=0; i<resultsDiv.size(); i++) {
System.out.println(i+1 + ". " + resultsDiv.get(i).getText());
}
Selenium を使用して Java でプログラミングしていますが、正しい XPath 式がわかりません。
誰かが私がこれを間違えた理由を理解し、このデータを正しく解析する方法についていくつかの指針を教えてもらえますか? 私は Selenium と XPaths に非常に慣れていませんが、仕事にはこれが必要です。
また、Selenium と XPath をすばやく学習するための良い情報源があれば、それらも大歓迎です!