package com.dw.lib.cli;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.dw.lib.test.jtidyTest;


public class YouDaoCLI {
	public static void printByClass(Document doc, String className) {
		Elements e = doc.getElementsByClass(className);
		if(e == null) return;
		String output = e.toString();
		if(output.equals("")) return;
		
		System.out.println(jtidyTest.html2text(output));
	}
	
	public static void printById(Document doc, String id) {
		Element e = doc.getElementById(id);
		if(e == null) return;
		String output = e.toString();
		if(output.equals("")) return;
		
		System.out.println(jtidyTest.html2text(output));
	}
	
	public static void printUsage() {
		System.out.println("youdao [word list]");
		System.out.println("youdao -p [word list]");
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			
			if(args.length <= 0) {
				printUsage();
			}
			
			boolean pronaunce = false;
			
			if(args[0] == "-p") {
				pronaunce = true;
			}
			
			//String word = args[0];
			
			String[] className = {
					
					};
			
			String[] IdList = {
					"phrsListTab",
					"webTransToggle",
					"tPETrans-all-trans",
					"collinsResult",
					"synonyms",
					"relWordTab",
					"bilingual",
					"originalSound",
					"authority"
					};

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

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

}

@@ -175,68 +175,124 @@
 s;%0A%0A
-import com.dw.lib.test.jtidyTest;%0A%0A%0Apublic class YouDaoCLI %7B
+public class YouDaoCLI %7B%0A%09%0A%09public static String html2text(String html) %7B%0A%09    return Jsoup.parse(html).text();%0A%09%7D%0A%09
 %0A%09pu
@@ -513,34 +513,24 @@
 out.println(
-jtidyTest.
 html2text(ou
@@ -753,18 +753,8 @@
 tln(
-jtidyTest.
 html
@@ -951,45 +951,8 @@
 ) %7B%0A
-%09%09// TODO Auto-generated method stub%0A
 %09%09tr
@@ -1749,46 +1749,8 @@
 ) %7B%0A
-%09%09%09// TODO Auto-generated catch block%0A
 %09%09%09e

fix youdao CLI