日期:2014-05-17 浏览次数:20896 次
	private list parsetable(string htmlstr) throws saxexception, ioexception {		reader reader = new stringreader(htmlstr);		inputsourceimpl inputsource = new inputsourceimpl(reader,				"aaa");		useragentcontext uacontext = new simpleuseragentcontext();		documentbuilderimpl builder = new documentbuilderimpl(uacontext);		document d = builder.parse(inputsource);		htmldocumentimpl document = (htmldocumentimpl) d;						nodelist  nl=document.getelementsbytagname("table");		arraylist<string[]> records=new arraylist<string[]>();		for (int i = 0; i < nl.getlength(); i++) {			htmltableelementimpl table=(htmltableelementimpl)nl.item(i);			htmlcollection rows=table.getrows();			for (int j = 0; j < rows.getlength(); j++) {				htmltablerowelementimpl row =(htmltablerowelementimpl)rows.item(j);				htmlcollection cells=row.getcells();				arraylist<string> cellsstr=new arraylist<string>();				for (int k = 0; k < cells.getlength(); k++) {					htmltablecellelementimpl cell =(htmltablecellelementimpl)cells.item(k);					cellsstr.add(cell.gettextcontent().tostring());				}				records.add(cellsstr.toarray(new string[0]));			}		}                return records;	}??