프로그래밍/자바

자바에서 크롬 웹드라이버 실행 파일을 따로 설치하지 않고 크롤링하기[vscode]

do121 2024. 1. 17. 14:35

파이썬과 같이 크롬 웹드라이버 실행 파일을 따로 설치하지 않고 아래의

웹드라이버 매니저  JAR 설치

https://jar-download.com/artifact-search/webdrivermanager

 

Download webdrivermanager JAR file with all dependencies

io.github.bonigarcia webdrivermanager 5.6.3 compile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '5.6.3' //Thanks for using https://jar-download.com libraryDependencies += "io.github.bonigarcia" % "webdrivermanager" % "5.6.3" //Thanks

jar-download.com

vscode에서 왼쪽하단의 레퍼런스 라이브러리에서 다운받은 웹드라이버 추가한다.

https://www.selenium.dev/downloads/에서 자바용 셀레니움을 받고 위에서 처럼 추가해 준다(라이브러리의 모든 JAR를 임포트해야 에러가 없음)

 

Downloads

Selenium automates browsers. That's it!

www.selenium.dev

 

아래와 같이 간단히 테스트 해본다.

public class App {
    
    public static void main(String[] args) throws Exception {
        System.out.println("Hello, World!");
        

        // WebDriverManager.chromedriver().setup();
        
		ChromeDriver driver = new ChromeDriver();
        
        
        driver.get("http://www.google.com");
        }
       }