我正在尝试弄清楚如何使用 Cobra/Lobo 工具包访问 DOM 节点(在此示例中为 <img> 节点)的 CSS 属性。我目前拥有的是:
UserAgentContext uacontext = new SimpleUserAgentContext();
DocumentBuilderImpl builder = new DocumentBuilderImpl(uacontext);
URL url = new URL(TEST_URI);
InputStream in = url.openConnection().getInputStream();
Reader reader = new InputStreamReader(in, "ISO-8859-1");
InputSourceImpl inputSource = new InputSourceImpl(reader, TEST_URI);
HTMLDocumentImpl d = (HTMLDocumentImpl) builder.parse(inputSource);
HTMLCollection images = d.getImages();
for (int i = 0; i < images.getLength(); i++) {
HTMLElementImpl n = (HTMLElementImpl) images.item(i);
AbstractCSS2Properties curr = n.getCurrentStyle();
System.out.println("Image " + i + ": " + curr.getPropertyValue("background-color"));
}
现在这似乎只给了我直接设置的样式——而不是继承或计算的样式。我怎样才能得到这些呢?
谢谢