我编写了一些代码来使用 xpath 和 Java 解析 html。html文件类似于:
<div class="field_row">
<label for="names">Names *</label>
<input id="address.A" type="text" maxlength="15" size="32" value="12345" name="address.work">
<span class="additional_info"> Information 1 </span>
</div>
<div class="field_row">
<label for="names">Names *</label>
<input id="address.B" type="text" maxlength="15" size="32" value="12345" name="address.work">
<span class="additional_info"> Information 2 </span>
</div>
和Java代码:
public static final Element INFOFIELD= Element.findXPath(".//*[@class='additional_info'");
会让我得到“信息1”;但是,我需要检索“信息 2”。因此,我使用:
public static final Element INFOFIELD= Element.findXPath(".//*[@class='additional_info' and @id='address.B']");
但是出现错误。你能给我一些提示吗?谢谢。一个。