2009-12-01 41 views
0

我想知道如何使用Cobra/Lobo工具包訪問DOM節點的CSS屬性(在本例中爲< img>節點)。我現在有的是:如何使用Cobra/Lobo HTML渲染器訪問DOM節點的屬性

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")); 
    } 

現在,這似乎只給我直接設置樣式 - 沒有繼承或計算樣式。我怎樣才能得到這些?

感謝

回答