Jump to content

Hiscore java code


SimeonCreel

Recommended Posts

I am playing with java and by using a html parser was able to create a class that strips high score info in a simple text format seperated by a pipe: let me know what u think! I got the html parser code from

 

 

 

http://htmlparser.sourceforge.net/

 

 

 


/*

* Created on Jul 14, 2006

*

*/

package my.runescape;

import org.htmlparser.Node;

import org.htmlparser.Parser;

import org.htmlparser.nodes.TagNode;

import org.htmlparser.nodes.TextNode;

import org.htmlparser.tags.LinkTag;

import org.htmlparser.tags.TableColumn;

import org.htmlparser.tags.TableRow;

import org.htmlparser.util.NodeIterator;

import org.htmlparser.util.NodeList;

import org.htmlparser.util.ParserException;

/**

*/

public class FirstTest {



private StringBuffer list = new StringBuffer();



public static void main(String[] args) {

	FirstTest mine = new FirstTest();

	mine.start();

	System.out.println(mine.list.toString());

}



private void start() {

	Parser parser;

	try {

		parser = new Parser ("http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=simeon_creel");

	    NodeIterator i = parser.elements (); 

	    while ((i.hasMoreNodes ())){

	    	this.processMyNodes(i.nextNode ());

	    }

	} catch (ParserException e) {

		// TODO Auto-generated catch block

		e.printStackTrace();

	}





}





/**

 */

private void processMyNodes(Node node) {

	// TODO Auto-generated method stub

     if (node instanceof TagNode)

     {

         // downcast to TagNode

         TagNode tag = (TagNode)node;     

         if(node instanceof TableRow){

         	// downcast to TableRow

         	TableRow tbRow = (TableRow)node;

         	if (tbRow.getColumnCount()>0) {

         		TableColumn[] tbCols = tbRow.getColumns();

         		for (int i = 0; i < tbCols.length; i++) {

	         		if (tbCols[i].getLastChild() instanceof LinkTag){

	         			LinkTag link = (LinkTag)tbCols[i].getLastChild();

	         			list.append("|"+link.getLinkText());

	         		}

		         	else if (tbCols[i].getLastChild() instanceof TextNode)

         		     {

         		         // downcast to TextNode

         		         TextNode text = (TextNode)tbCols[i].getLastChild();

         		         // do whatever processing you want with the text



         		         if (!text.getText().equalsIgnoreCase(" ")) list.append("|"+text.getText());

         		     }//end of else if

                }//end of For loop

         	}

         }

         NodeList nl = tag.getChildren ();

         if (null != nl){

             try {

				for (NodeIterator i = nl.elements (); i.hasMoreNodes(); )

				     processMyNodes (i.nextNode ());

			} catch (ParserException e) {

				// TODO Auto-generated catch block

				e.printStackTrace();

			}// End of Catch

         }// End of if null

     }// End of if node



    }//end of function



}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.