Last active
December 14, 2015 15:09
-
-
Save pjc0247/5106008 to your computer and use it in GitHub Desktop.
클래스 이름 수정
MealLibrary -> Meal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package anz.library.meal; | |
import java.io.IOException; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.List; | |
import net.htmlparser.jericho.Element; | |
import net.htmlparser.jericho.Segment; | |
import net.htmlparser.jericho.Source; | |
public class Meal | |
{ | |
static Source source; | |
private static final String urlPrefix = "http://hes."; | |
private static final String urlSuffix = ".go.kr/sts_sci_md01_001.do?schulCode="; | |
private static final String paramCrse = "&schulCrseScCode="; | |
private static final String paramKnd = "&schulKndScCode="; | |
private static final String paramMeal = "&schMmealScCode="; | |
public static String[] getDate(String CountryCode, String schulCode, String schulCrseScCode, String schulKndScCode, String schMmealScCode) | |
{ | |
String[] date = new String[7]; | |
String url = urlPrefix + CountryCode + urlSuffix + schulCode + paramSrse + schulCrseScCode + paramKnd + schulKndScCode + paramMeal + schMmealScCode; | |
try { | |
source = new Source(new URL(url)); | |
} | |
catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
source.fullSequentialParse(); | |
List table = source.getAllElements("table"); | |
for (int i = 0; i < table.size(); i++) { | |
if (((Element)table.get(i)).getAttributeValue("class").equals("tableType6")) { | |
List tr = ((Element)table.get(i)).getAllElements("tr"); | |
List th = ((Element)tr.get(0)).getAllElements("th"); | |
for(int j = 0; j <= 6; j ++){ | |
date[j] = ((Element)th.get(j+1)).getContent().toString(); | |
} | |
break; | |
} | |
} | |
return date; | |
} | |
public static String[] getMeal(String CountryCode, String schulCode, String schulCrseScCode, String schulKndScCode, String schMmealScCode) { | |
String[] content = new String[7]; | |
String url = urlPrefix + CountryCode + urlSuffix + schulCode + paramSrse + schulCrseScCode + paramKnd + schulKndScCode + paramMeal + schMmealScCode; | |
try { | |
source = new Source(new URL(url)); | |
} | |
catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
source.fullSequentialParse(); | |
List table = source.getAllElements("table"); | |
for (int i = 0; i < table.size(); i++) { | |
if (((Element)table.get(i)).getAttributeValue("class").equals("tableType6")) { | |
List tr = ((Element)table.get(i)).getAllElements("tr"); | |
List title = ((Element)tr.get(2)).getAllElements("th"); | |
if (((Element)title.get(0)).getContent().toString().equals("식재료")) | |
{ | |
List tdMeal = ((Element)tr.get(1)).getAllElements("td"); | |
for(int j = 0; j <= 6; j++){ | |
content[j] = ((Element)tdMeal.get(j)).getContent().toString(); | |
content[j] = content[j].replace("<br />", "\n"); | |
} | |
break; | |
} | |
for(int j = 0; j <= 6; j++) | |
content[j] = null; | |
} | |
} | |
return content; | |
} | |
public static String[] getKcal(String CountryCode, String schulCode, String schulCrseScCode, String schulKndScCode, String schMmealScCode) { | |
String[] content = new String[7]; | |
String url = urlPrefix + CountryCode + urlSuffix + schulCode + paramSrse + schulCrseScCode + paramKnd + schulKndScCode + paramMeal + schMmealScCode; | |
try { | |
source = new Source(new URL(url)); | |
} | |
catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
source.fullSequentialParse(); | |
List table = source.getAllElements("table"); | |
for (int i = 0; i < table.size(); i++) { | |
if (((Element)table.get(i)).getAttributeValue("class").equals("tableType6")) { | |
List tbody = ((Element)table.get(i)).getAllElements("tbody"); | |
List __tr = ((Element)tbody.get(0)).getAllElements("tr"); | |
List __th = ((Element)__tr.get(15)).getAllElements("th"); | |
if (((Element)__th.get(0)).getContent().toString().equals("에너지(kcal) ")) { | |
List td = ((Element)__tr.get(15)).getAllElements("td"); | |
for(int j = 0; j <= 6; j++) | |
content[j] = ((Element)td.get(j)).getContent().toString(); | |
break; | |
} | |
for(int j = 0; j <= 6; j++) | |
content[j] = null; | |
break; | |
} | |
} | |
return content; | |
} | |
public static String[] getPeople(String CountryCode, String schulCode, String schulCrseScCode, String schulKndScCode, String schMmealScCode) { | |
String[] content = new String[7]; | |
String url = urlPrefix + CountryCode + urlSuffix + schulCode + paramSrse + schulCrseScCode + paramKnd + schulKndScCode + paramMeal + schMmealScCode; | |
try { | |
source = new Source(new URL(url)); | |
} | |
catch (MalformedURLException e) | |
{ | |
e.printStackTrace(); | |
} | |
catch (IOException e) | |
{ | |
e.printStackTrace(); | |
} | |
source.fullSequentialParse(); | |
List table = source.getAllElements("table"); | |
for (int i = 0; i < table.size(); i++) { | |
if (((Element)table.get(i)).getAttributeValue("class").equals("tableType6")) { | |
List tbody = ((Element)table.get(i)).getAllElements("tbody"); | |
List __tr = ((Element)tbody.get(0)).getAllElements("tr"); | |
List __th = ((Element)__tr.get(15)).getAllElements("th"); | |
if (((Element)__th.get(0)).getContent().toString().equals("에너지(kcal) ")) { | |
List td = ((Element)__tr.get(15)).getAllElements("td"); | |
for(int j = 0; j <= 6; j++) | |
content[j] = ((Element)td.get(j)).getContent().toString(); | |
break; | |
} | |
for(int j = 0; j <= 6; j++) | |
content[j] = null; | |
break; | |
} | |
} | |
return content; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment