我試圖使用W3C DOMXML解析器
<html>
<div id='token' style='display:none;'>
n0Y7ezLlIYA8R0K54rEmHaTOraBQVSPDjQaGlQxlGso4jdVN1kRxtcfskEs=
</div>
</html>
提取n0Y7ezLlIYA8R0K54rEmHaTOraBQVSPDjQaGlQxlGso4jdVN1kRxtcfskEs=
但我似乎被卡住
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(con.getInputStream());
NodeList list = doc.getElementsByTagName("div");
有人請點我的一些基本教程,幫助我解決我的困境。 謝謝。
編輯:
好吧,我得到它的工作,但它似乎笨重
String token;
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(con.getInputStream());
Element root = doc.getDocumentElement();
NodeList items = root.getElementsByTagName("html");
for(int i = 0; i < items.getLength(); i++) {
Message message = new Message();
Node item = items.item(i);
NodeList properties = item.getChildNodes();
for(int j = 0; j < properties.getLength(); j++) {
Node property = properties.item(j);
String name = property.getNodeName();
if(name.equalsIgnoreCase("div")) {
token = property.getFirstChild().getNodeValue());
}
}
}
一點點有一個漂亮的方式來獲得令牌?
你怎麼卡? – 2010-05-20 04:07:58
好吧我編輯了一下 – lemon 2010-05-20 04:22:38
DOM是你會考慮的唯一選擇嗎? – 2010-05-20 05:49:56