package com.dw.lib.test;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.*;
import org.jsoup.select.Elements;
public class jsoupTest {
	
	public static void printByClass(Document doc, String className) {
		try {
			Elements e = doc.getElementsByClass(className);
			String output = e.toString();
			if (output.equals(""))
				return;

			System.out.println(jtidyTest.html2text(new String(output.getBytes("UTF-8"))));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void printUsage() {
		System.out.println("jdict [word list]");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			
			if(args.length <= 0) {
				printUsage();
			}
			
			//String word = args[0];
			
			String[] className = {"dict-basic-ul", 
					"layout detail", 
					"layout dual",
					"layout en", 
					"layout sort",
					"layout anno",
					"layout auth",
					"layout nfo",
					"layout nwd"
					};

			for (int i = 0; i < args.length; i++) {
				System.out.println(String.format("%s: ", args[i]));

				Document doc = Jsoup.connect(String.format("http://dict.cn/%s", args[i])).get();
				for (String s : className)
					printByClass(doc, s);
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

@@ -226,25 +226,16 @@
 Name) %7B%0A
-%09%09try %7B%0A%09
 %09%09Elemen
@@ -278,17 +278,16 @@
 ame);%0A%09%09
-%09
 String o
@@ -312,14 +312,12 @@
 ();%0A
-%09
 %09%09if
- 
 (out
@@ -335,21 +335,17 @@
 %22%22))
-%0A%09%09%09%09
+ 
 return;%0A
 %0A%09%09%09
@@ -340,18 +340,19 @@
 return;%0A
-%0A
 %09
+%09%0A
 %09%09System
@@ -388,101 +388,17 @@
 ext(
-new String(output.getBytes(%22UTF-8%22))));%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D
+output));
 %0A%09%7D%0A

change back to default encoding