最近在编写爬虫程序,这里简单的做下笔记。
阅读注意事项
- 需要一台服务器(阿里ESC)这种,分配的公网ip。
- 这里使用的yum安装,所以环境配置都创建好了,不需要在手动修改。
准备工作
安装Java、maven、git、selenium运行环境
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
|
-> yum install java-1.8.0-openjdk-devel.x86_64 -> java -version openjdk version "1.8.0_262" OpenJDK Runtime Environment (build 1.8.0_262-b10) OpenJDK 64-Bit Server VM (build 25.262-b10, mixed mode) -> yum install maven -> mvn -version Java version: 1.8.0_262, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/jre Default locale: zh_CN, platform encoding: UTF-8 OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix" -> yum install git git version 1.8.3.1
-> ls -al ~/.ssh
-> ssh-keygen -t rsa -C “you email@gamil.com”
-> cat ~/.ssh/id_rsa.pub
-> wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm -> yum localinstall google-chrome-stable_current_x86_64.rpm
-> google-chrome --version Google Chrome 85.0.4183.83
-> yum install chromedriver -> chromedriver -version ChromeDriver 84.0.4147.89
|
- 注意 google-chrome 和 chromedriver版本是需要对应的具体可以到官方查看。
- 在centos上运行需要配置下关键参数
1 2 3 4 5 6 7
| ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.addArguments("--headless"); chromeOptions.addArguments("--disable-gpu"); chromeOptions.addArguments("--no-sandbox"); chromeOptions.setHeadless(true); return new ChromeDriver(chromeOptions);
|
1 2
| System.setProperty("webdriver.chrome.chromedriver", "/usr/bin/chromedriver"); # 具体可以通过 whereis chromedriver查看。
|
参考文献
CentOS使用yum安装jdk