引言

虽然尝试了,但是最后大概还是 X11 的问题,只能在有图形化的界面运行,无图形化的命令行连无头浏览器都无法运行。所以我寻思着,要么就用 X11 转发,要么远程操控 (虽然有点奇怪但是这就算简单的).

过程

安装依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Prerequisites
sudo apt install -y unzip xvfb libxi6 libgconf-2-4
sudo apt install default-jdk

# Install Google Chrome
## export https_proxy=http://10.9.65.31:7890 http_proxy=http://10.9.65.31:7890 all_proxy=http://10.9.65.31:7890
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
## sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub -x http://10.9.65.31:7890 | apt-key add
sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list"
sudo apt -y update
sudo apt -y install google-chrome-stable
google-chrome --version

# Installing ChromeDriver
wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/121.0.6167.85/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
sudo mv chromedriver-linux64 /usr/bin/chromedriver
sudo chown root:root /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
## apt install chromium-chromedriver
chromedriver -v

java 版安装

1
2
3
4
5
6
# Download Required Jar Files
wget http://selenium-release.storage.googleapis.com/4.0/selenium-server-standalone-4.0.0-alpha-2.jar
mv selenium-server-standalone-4.0.0-alpha-2.jar selenium-server-standalone.jar

# Start Chrome via Selenium Server
xvfb-run java -Dwebdriver.chrome.driver=/usr/bin/chromedriver -jar selenium-server-standalone.jar

安装 python 版

1
pip install -U selenium

chrome

试过了,能打开但是不管啥用…

1
2
3
# chrome --no-sandbox --remote-debugging-port=13888  --user-data-dir=/data/chrome/13888 --ignore-certificate-errors
google-chrome --no-sandbox --remote-debugging-port=13888 --user-data-dir=~/chrome/13888 --ignore-certificate-errors --no-sandbox --allowed-origins="*"
chromedriver --port=13889 --whitelisted-ips --enable-webgl --no-sandbox --disable-dev-shm-usage --allowed-origins="*"

引用

  1. How to Setup Selenium with ChromeDriver on Ubuntu 22.04, 20.04 & 18.04
  2. selenium-release.storage.googleapis.com/xml
  3. selenium-release.storage.googleapis.com/index.html
  4. seleniuim chromedriver 固定 chrome 浏览器端口以及远程调试(windows & linux)python