2

ここでコードを入力

<table style=”padding: 0px; margin: 0px;” cellpadding="0" cellspacing="0" width="626" align="center" bgcolor="White" border="0">
<tr>
<td style=”vertical-align: top;” height="61" valign="top" bgcolor="#0492CB"><a href="http://www.aoec.com"> <img alt="AoEC" src="http://www.aoec.com/email/mute/images/header.gif" style="width: 626px; height: 61px;" border="0" /></a></td>
</tr>
</table>

Javaコーディングは

Document doc = Jsoup.parse(code);
Elements elements = doc.getElementsByAttribute("style");
for(int se=0;se<elements.size();se++)
{
 System.out.println(elements.get(se).attr("style"));
}

出力は

padding:;
vertical-align:;

上記のコードで getElementsByAttribute("style") が機能していません..

4

2 に答える 2

2
于 2012-10-24T11:17:27.697 に答える
1

これはすでに廃止されていると思います。メソッドを使用する必要があります.select();。また、単純な for は NullPointerExceptions をスローする可能性があるため、ループ中に foreach または iterator を使用することをお勧めします。

ここでドキュメントを見つけることができます

しかし、私はそれを使用しません:

//That should get you all tags that have the style attribute
Elements elements = doc.select("[style]");

//That foreach should avoid exceptions, and loop through the collection 
for(Element element : elements) {
    //The print gets a little cleaner too!
    System.out.println(element.attr("style"));
}
于 2012-10-25T11:23:50.677 に答える