我试图使用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