这是代码的有用部分:
java.util.List<Element> elems = src.getAllElements();
Iterator it = elems.iterator();
Element el;
String key,value,date="",place="";
String [] data;
int k=0;
Segment content;
String contentstr;
String classname;
while(it.hasNext()){
el = (Element)it.next();
if(el.getName().equals("span"))
{
classname=el.getAttributeValue("class");
if(classname.equals("edit_body"))
{
//java.util.List<Element> elemsinner = el.getChildElements();
//Iterator itinner = elemsinner.iterator();
content=el.getContent();
contentstr=content.toString();
if(true)
{
System.out.println("Done!");
System.out.println(classname);
System.out.println(contentstr);
}
}
}
}
没有输出。但是,如果我删除if(classname.equals("edit_body"))
它确实打印的条件(在其中一次迭代中):
Done!
edit_body
"I honestly think it is better to be a failure at something you love than to be a success at something you hate."
无法获取错误部分...帮助!
我正在使用外部 java 库 BTW 进行 html 解析。
顺便说一句,输出开始时有两个错误,在两种情况下都存在,有或没有 if 条件:
Dec 20, 2012 11:53:11 AM net.htmlparser.jericho.LoggerProviderJava$JavaLogger error SEVERE: EndTag br at (r1992,c60,p94048) not recognised as type '/normal' because its name and closing delimiter are separated by characters other than white space
Dec 20, 2012 11:53:11 AM net.htmlparser.jericho.LoggerProviderJava$JavaLogger error SEVERE: Encountered possible EndTag at (r1992,c60,p94048) whose content does not match a registered EndTagType
希望不会导致错误
好的伙计们,请有人解释我!"edit_body".equals(el.getAttributeValue("class")) 工作!!