import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.BufferedWriter;
import java.io.OutputStreamWriter;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
public class Youtube
{
/**
* Keeps track of whether the first reading has been performed.
*/
protected boolean readFlag = false;
/*
* The main program, which can be executed from the command line
*/
public static void main(String [] args)
{
int liLine = 0;
int liDataIndex = 0;
int liMode = 0;
ArrayList datalist = new ArrayList();
BufferedReader br = null;
String line;
String title;
String imgurl;
String watch;
// int chkInt =0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\htmlp\\eve.html"),"utf-8"));
line = "";
title = "";
imgurl = "";
watch = "";
while ((line = br.readLine()) != null) {
if(line.indexOf("yt-uix-sessionlink yt-uix-tile-link spf-link yt-ui-ellipsis yt-ui-ellipsis-2") > 0)
{
title = line.substring(line.indexOf("title=")+7,line.indexOf("aria-describedby")-3);
watch = line.substring(line.indexOf("watch?v=")+8,line.indexOf(">김이브")-1);
liMode = 1;
// datalist.add(title);
}
if(line.indexOf("data-thumb=") > 0)
{
imgurl = line.substring(line.indexOf("data-thumb=")+12,line.indexOf(" src=")-1);
System.out.println(title + "," + imgurl + "," + watch);
liMode = 2;
datalist.add("'"+title+"', '"+watch+"', 'Y', '', '"+imgurl+"');");
}
// if(chkInt == 500) break; // 10 Line
// chkInt ++;
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null) {
br.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
int seq = 1;
try {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("eveOut.txt"), "utf-8"));
for(int i= (datalist.size()-1); i >= 0 ; i--) {
String outStr = (String)datalist.get(i);
writer.write("INSERT INTO tb_cast_tmp (cast_seq, cast_title, castid, use_yn, regdate, author_url) VALUES ("+seq+ ","+outStr );
writer.write(seq +"," +outStr);
writer.write("\r\n");
seq ++;
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
'세상이야기' 카테고리의 다른 글
ORACLE 요일 구하는 방법 (0) | 2017.02.20 |
---|---|
mysql replace 예제 소스 (0) | 2017.02.19 |
Java File Read/Write 예제소스, 한글 깨지는 현상 해결 (0) | 2017.02.17 |
Java File Read/Write 예제 (파일 읽기/쓰기 예제 )소스 (0) | 2017.02.17 |
MySql 문자열 합치기 (0) | 2016.12.19 |