linux系统安装Chrome用于Selenium
下载chrome
1
| wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
安装chrome
1 2
| sudo dpkg -i google-chrome*.deb sudo apt-get install -f
|
可能会遇到
1
| dpkg: error: dpkg status database is locked by another process
|
解决办法
1 2 3
| sudo rm /var/lib/dpkg/lock sudo dpkg --configure -a sudo rm /var/lib/apt/lists/lock
|
安装chromedriver
查看chrome版本
下载对应版本chromedriver
1
| wget -N http://chromedriver.storage.googleapis.com/版本号/chromedriver_linux64.zip
|
解压chromedriver
1
| unzip chromedriver_linux64.zip
|
Java配置
1 2 3 4 5 6 7 8 9 10 11 12 13
| @Bean public WebDriver webDriver() { System.setProperty(usr, path); ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setHeadless(true); chromeOptions.addArguments("headless"); chromeOptions.addArguments("no-sandbox"); chromeOptions.addArguments("--start-maximized"); chromeOptions.addArguments("--disable-gpu"); return new ChromeDriver(chromeOptions); }
|