Just wrote an HTML file parser to generate a simple Element tree, including all elements. Although there are many parsing of HTML's API, just I use a little bit of function, and write it very quickly. Class: HTMLELEMENT, HTMLPARSER, LoginAgent purpose is to use the program to automatically download the message page, use the httpurlconnection post to log in, search all INPUT of LoginForm, just specifically set the user password.
However, after the page is open, the link inside actually wants to POST data, the problem is that the value of INPUT is set, so INPUTSTREAM downloads no value, fainted! ! Nothing.
Package com.forum; import java.io. *; / ** * *
Title: p> *
Description: p> *
Copyright: CopyRight (C) 2004 P > *
Company: p> * @Author zfzheng Pig God * @version 1.0 * / public class htmlparser {
public static HTMLElement buildHTMLElementFromFile (String fileName) throws IOException {BufferedReader br = new BufferedReader (new InputStreamReader (new FileInputStream (fileName), "GB2312")); String line; StringBuffer result = new StringBuffer (); while ((line = br. Readline ())! = null) {Result.Append (line);} br.close (); return buildhtmlelementfromstring (result.toString ());}
public static HTMLElement buildHTMLElementFromString (String data) {HTMLElement root = new HTMLElement (); HTMLElement parent = root; root.setPrototypeString ( "root node"); HTMLElement e = null; char [] chs = data.toCharArray (); char ch INT i = 0; stringbuffer tagname = new stringbuffer (); boolean incommont = false; boolean tagdefinebegin = false; boolean tagdefinend = false;
While (i
Switch (ch) {case '<': {IF (i 1
{TagDefinend = true; tagname.setlength (0);} Break;} DEFAULT: {if (tagDefineBegin) {tagname.Append (ch);} else.Append (CH);} Break;} } I ;} return root;
public static void main (String [] args) {HTMLParser.buildHTMLElementFromString ( "
}