-
Notifications
You must be signed in to change notification settings - Fork 4
/
WebtoonImageCrawling2.java
58 lines (42 loc) · 1.59 KB
/
WebtoonImageCrawling2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.Webtoon;
import java.awt.image.BufferedImage;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import javax.imageio.ImageIO;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class WebtoonImageCrawling2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("À¥Å÷Á¦¸ñ : ");
String wtName = sc.next();
System.out.print("½ÃÀÛÈ : ");
int startNo = sc.nextInt();
System.out.print("³¡È : ");
int endNo = sc.nextInt();
String wtUrl = "http://comic.naver.com/webtoon/detail.nhn?titleId=131385&no=";
try {
for (int n = startNo; n <= endNo; n++) {
Document webtoonPage = Jsoup.connect(wtUrl + n).get();
// System.out.println(webtoonPage.select(".wt_viewer > img"));
Elements imgUrl = webtoonPage.select(".wt_viewer > img");
for (int i = 0; i < imgUrl.size(); i++) {
System.out.println(imgUrl.get(i).attr("src"));
String src = imgUrl.get(i).attr("src");
URL url = new URL(src);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Referer", src);
BufferedImage img = ImageIO.read(conn.getInputStream());
FileOutputStream out = new FileOutputStream("C:\\Users\\pc-13\\Desktop\\image\\webtoon\\" + wtName + "_" + n + "_" + (i + 1) + ".jpg");
ImageIO.write(img, "jpg", out);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}