์ ๊ณต ์ง์์ด ์์ด์ ํ๋ก๊ทธ๋๋ฐ๊ฐค ๊ฐ์ ๋ฐ ์ง๋ฌธ ์ฌ๋ฆฌ๊ธด ๊ทธ๋์ ์ฌ๊ธฐ๋ค ์..
์ฌ๋์ค๋ผ๋ ๊ฒ์ ๋ชจ๋ ๋ง๋๋ ์ค์ธ๋ฐ gpt์ ์์งํด์ ์ฐ๋ค๊ฐ ๋๋ฌด์ง ์ดํดํ ์ ์๋ ๋ฒ๊ทธ๊ฐ ๋์์
getLinks()๋ ๊ณต๋ต๊ธ ๋งํฌ์์ ์นด๋ ์ด๋ฆ๊ณผ ์ฐ๊ฒฐ๋ ๋งํฌ๋ฅผ ํฌ๋กค๋งํด์ hashmap์ ์ ์ฅํด์ ๋ฆฌํดํ๋ย ํจ์๊ณ
getComment()๋ ๋งค๊ฐ๋ณ์๋ก ๋ฐ์ ๋์ ๊ธ์์ ๋๊ธ ์ค ํ๋๋ฅผ ๋๋ค์ผ๋ก ๋ฆฌํดํ๋ ํจ์์ธ๋ฐ
getLinks()๋ ์ ์์ ์ผ๋ก ์๋ํด์ ์นด๋ ์ด๋ฆ๊ณผ ๋งํฌ๊ฐ ์ ๋งค์นญ์ด ๋๋๋ฐ getComment๋ ์๊พธ no comment๋ง ๋ฆฌํดํจ
setSSL()์ ์ค๋ฅ ๋จ๊ธธ๋ ๊ตฌ๊ธ์ ๊ฒ์ํด์ ๋์จ ๊ฑฐ ๋ณต๋ถํจ
public static void setSSL() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultHostnameVerifier(
new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
public static HashMap<String, String> getLinks() {
String url = "https://gall.dcinside.com/mgallery/board/view/?id=slay&no=171241";
try {
if(url.indexOf("https://") >= 0) {
JsoupWeb.setSSL();
}
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("a.lnk[href*='slay']");
HashMap<String, String> linkMap = new HashMap<>();
for (Element link : links) {
String linkText = link.text();
String linkHref = link.attr("abs:href");
linkMap.put(linkText, linkHref);
}
return linkMap;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
public static String getComment(String link) {
String url = link;
try {
if(url.indexOf("https://") >= 0) {
JsoupWeb.setSSL();
}
Document doc = Jsoup.connect(url).get();
Elements paragraphs = doc.select("p.usertxt.ub-word");
List<String> texts = new ArrayList<>();
for (Element paragraph : paragraphs) {
texts.add(paragraph.text());
}
if (!texts.isEmpty()) {
Random random = new Random();
int randomIndex = random.nextInt(texts.size());
return texts.get(randomIndex);
} else {
return "no comment";
}
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultHostnameVerifier(
new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
);
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
public static HashMap<String, String> getLinks() {
String url = "https://gall.dcinside.com/mgallery/board/view/?id=slay&no=171241";
try {
if(url.indexOf("https://") >= 0) {
JsoupWeb.setSSL();
}
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("a.lnk[href*='slay']");
HashMap<String, String> linkMap = new HashMap<>();
for (Element link : links) {
String linkText = link.text();
String linkHref = link.attr("abs:href");
linkMap.put(linkText, linkHref);
}
return linkMap;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
public static String getComment(String link) {
String url = link;
try {
if(url.indexOf("https://") >= 0) {
JsoupWeb.setSSL();
}
Document doc = Jsoup.connect(url).get();
Elements paragraphs = doc.select("p.usertxt.ub-word");
List<String> texts = new ArrayList<>();
for (Element paragraph : paragraphs) {
texts.add(paragraph.text());
}
if (!texts.isEmpty()) {
Random random = new Random();
int randomIndex = random.nextInt(texts.size());
return texts.get(randomIndex);
} else {
return "no comment";
}
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
} catch (KeyManagementException e) {
throw new RuntimeException(e);
}
}
ํฌ๋กฌ์ฐํด๋ฆญ - ์์ค๋ณด๊ธฐ ํ๋ฉด comment ์๋๊ฑฐ ์ ์ ์์. ๊ธ์ ์๋ js์์ ๋ฐ๋ก ์์ฒญํ๋ ๋ฐฉ์์
๋์ ํฌ๋กค๋ง ํ๋ ค๋๊ฑฐ์? ์ฝ์ง ์์๊ฑฐ์
์ง์ง๋ค.. ๋ณธ๋ฌธ์ ์๋๋ฐ ๋๊ธ์ ์๊ตฌ๋ ํน์ ์ด๋ป๊ฒ ํด์ผํ ์ง ๋๋ต์ด๋ผ๋ ์๋ ค์ค์ ์์๊น?ใ ใ ๊ฒ์์ด๋ผ๋..
๋ณดํต์ selenium, undetected-chromebrowser ๊ฐ์ ํค๋๋ฆฌ์ค ๋ธ๋ผ์ฐ์ ์จ์ ์ค์ ๋ธ๋ผ์ฐ์ ๋์์ด๋ ๋์ผํ๊ฒ ๋ก๋ฉ ๊ธฐ๋ค๋ ค์ ๋ฐ์ดํฐ ๋ฝ์์ด
ใ ใ ๊ฐ์ฌ๊ฐ์ฌ ํจ ํด๋ณผ๊ฒ