我正在尝试了解如何使用Cobra/Lobo工具包访问DOM节点(在本例中为节点)的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"));
}现在,这似乎只给了我直接设置的样式,而不是继承或计算的样式。我怎么也能得到这些呢?
谢谢
发布于 2009-12-01 23:34:53
我希望您需要使用Class HTMLElementImpl的getComputedStyle方法。
https://stackoverflow.com/questions/1826843
复制相似问题