package com.dw.lib.test;

import java.io.IOException;

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


public class YouDaoCLI {
	public static void printByClass(Document doc, String className) {
		Elements e = doc.getElementsByClass(className);
		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);
		String output = e.toString();
		if(output.equals("")) return;
		
		System.out.println(jtidyTest.html2text(output));
	}
	
	public static void printUsage() {
		System.out.println("youdao [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 = {
					
					};
			
			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();
		}
	}

}

@@ -315,16 +315,40 @@
 sName);%0A
+%09%09if(e == null) return;%0A
 %09%09String
@@ -363,32 +363,32 @@
 = e.toString();%0A
-
 %09%09if(output.equa
@@ -557,16 +557,40 @@
 Id(id);%0A
+%09%09if(e == null) return;%0A
 %09%09String
@@ -783,16 +783,63 @@
 ist%5D%22);%0A
+%09%09System.out.println(%22youdao -p %5Bword list%5D%22);%0A
 %09%7D%0A%09%0A%09pu
@@ -948,24 +948,24 @@
 gth %3C= 0) %7B%0A
-
 %09%09%09%09printUsa
@@ -979,16 +979,106 @@
 %09%09%7D%0A%09%09%09%0A
+%09%09%09boolean pronaunce = false;%0A%09%09%09%0A%09%09%09if(args%5B0%5D == %22-p%22) %7B%0A%09%09%09%09pronaunce = true;%0A%09%09%09%7D%0A%09%09%09%0A
 %09%09%09//Str

fix bugs for not-existing id