我有HTML格式的字符串,我試圖使用Jsoup獲取所有屬性及其值。在jsoup中獲取html字符串中的所有屬性
字符串是
String string=
"<button class=submit btn primary-btn flex-table-btn js-submit type=submit>Sign in</button>";
Document doc = Jsoup.parse(string);
try {
org.jsoup.nodes.Attributes attrs = doc.attributes();
for(org.jsoup.nodes.Element element : doc.getAllElements())
{
for(Attribute attribute : element.attributes())
{
System.out.println(attribute.getKey() + " --::-- "+attribute.getValue() );
}
}
} catch (Exception e) {
e.printStackTrace();
}
我期望的輸出是::
key: **class** , Value is: **submit btn primary-btn flex-table-btn js-submit**
key: **type** , Value is: **submit**
但我得到的是這種
key: class , Value is: submit key: btn , Value is: key: primary-btn , Value is: key: flex-table-btn , Value is: key: js-submit , Value is: key: type , Value is: submit
這是因爲引號的。如果我用
String string=
"<button class='submit btn primary-btn flex-table-btn js-submit' type='submit'> Sign in</button>";
我會得到我想要的輸出。但我試圖得到沒有引號。