Last active
June 2, 2021 09:28
-
-
Save youngjinmo/4d7d92e75c9bb57caa0cf9598de85556 to your computer and use it in GitHub Desktop.
Jsoup이용해서 동행복권 사이트에서 금주 로또 당첨번호 파싱
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 jsoupsample; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Timer; | |
import java.util.TimerTask; | |
import org.jsoup.Jsoup; | |
import org.jsoup.nodes.Document; | |
import org.jsoup.select.Elements; | |
public class jsoupExam { | |
public static void main(String[] args) throws IOException { | |
String url = "https://www.dhlottery.co.kr/common.do?method=main"; | |
log(url); | |
} | |
static ArrayList<Integer> getLottoNums(String url) throws IOException { | |
Document doc = Jsoup.connect(url).get(); | |
// 동행복권 사이트에서 로또 번호 추출 | |
Elements parseNumbers = doc.select("#numView"); | |
String str = parseNumbers.get(0).text(); | |
String[] lottoNums = str.split(" "); | |
ArrayList<Integer> arrayList = new ArrayList<>(); | |
for (int i = 0; i < lottoNums.length; i++) { | |
if(i==0 || i==7) { | |
continue; | |
} else { | |
// log(lottoNums[i]); | |
arrayList.add(Integer.parseInt(lottoNums[i])); | |
} | |
} | |
return arrayList; | |
} | |
// 콘솔에 출력하는 함수 | |
static void log(String url) throws IOException { | |
ArrayList<Integer> ar = getLottoNums(url); | |
System.out.println(Arrays.toString(ar.toArray())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment