IT/java


html에 존재하지 않는 element 가져오려고 하면 아래와 같은 에러가 발생 Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".protected_form"} (Session info: chrome=114.0.5735.110) For documentation on this error, please visit: https://selenium.dev/exceptions/#no_such_element Build info: version: '4.9.0', revision: 'd7057100a..


href 속성 값: null Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.replace(java.lang.CharSequence, java.lang.CharSequence)" because "hrefValue" is null at tistoryMavenProject.tistoryAuto.visitTistory(tistoryAuto.java:222) at tistoryMavenProject.tistoryAuto.main(tistoryAuto.java:295) null 처리 하지 않으면 위와 같은 에러가 발생함 String myString = /* 어떤 값이든 될 수 있음 */; if (myString != ..

public class CheckIfStringIsNumericExample { public static void main(String[] args) { // 숫자로만 구성된 문자열 String numericString = "12345"; // 숫자로만 구성되지 않은 문자열 String nonNumericString = "abc123"; // 숫자로만 구성되었는지 확인 boolean isNumeric = isNumeric(numericString); System.out.println(numericString + "은 숫자로만 구성되어 " + (isNumeric ? "있습니다." : "있지 않습니다.")); isNumeric = isNumeric(nonNumericString); System.out.pri..

public class ExcludeSubstringExample { public static void main(String[] args) { String originalString = "highschool"; String substringToExclude = "school"; // replace 메서드를 사용하여 특정 부분을 제외한 문자열 추출 String extractedString = originalString.replace(substringToExclude, ""); System.out.println("추출된 문자열: " + extractedString); } }

public class SubstringExample { public static void main(String[] args) { String mainString = "Hello, World!"; String subString = "Hello"; // contains 메서드를 사용하여 특정 문자열이 포함되어 있는지 확인 if (mainString.contains(subString)) { System.out.println("mainString에는 subString이 포함되어 있습니다."); } else { System.out.println("mainString에는 subString이 포함되어 있지 않습니다."); } } }

import java.util.ArrayList; import java.util.List; public class StringListExample { public static void main(String[] args) { // String 타입의 리스트 선언 List stringList = new ArrayList(); // 리스트에 값 추가 stringList.add("첫 번째 문자열"); stringList.add("두 번째 문자열"); stringList.add("세 번째 문자열"); // 리스트 출력 System.out.println("String List: " + stringList); // 리스트 크기 확인 System.out.println("리스트 크기: " + stringList.size..


위에 소스를 설명하자면, 구글에 들어가서, q라는 name의 element를 찾는다.(q는 구글 검색창) 검색어를 설정하고 submit으로 검색 시작 action을 줄 수 있도록 추가를 하고, PAGE_DOWN 키를 연타한다. 많은 수의 주소를 얻기 위함. RVQdVd class는 구글 더보기 버튼의 클래스임. 클릭을 누르면 검색결과가 더 많이 리스트업 된다. tjvcx의 클래스는 url이다. 이번에는 리스트로 받아서, 다수의 데이터를 한번에 가져올 수 있다. 아래 소스는 받아온 리스트를 사이즈 크기 만큼 for문 돌려서 텍스트 확인하기. (희안하게 홀수 index에는 주소값이 들어있지 않아서 i를 짝수 단위로 올린걸 알 수 있다. 결과물


1. webdriver 초기 설정 및 chromeDriver 연동 및 동작 확인 직접 jar를 추가하여 진행하려 했으나, 버전 이슈 때문에 하나하나 계속 버전 바꿔가면서 jar 추가하는 번거로움이 존재. maven 설정을 하여, 직접 dependency를 추가하여 버전을 맞추기 시작. 허나 아래와 같은 오류가 발생 SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Starting Ch..