In summary, there are probably three parts
1. Install the library
2. Adapted version
3. Code settings
The first part of the installation library:
pip install selenium
The second part is adapted version:
The version of chromedirver and chrome browser should be adapted, otherwise it will report an error
The version control relationship between chromedriver and chrome is
--------以下为2019年兼容版本对照表-------
ChromeDriver 76.0.3809.12 (2019-06-07)---------Supports Chrome version 76
ChromeDriver 75.0.3770.8 (2019-04-29)---------Supports Chrome version 75
ChromeDriver v74.0.3729.6 (2019-03-14)--------Supports Chrome v74
ChromeDriver v2.46 (2019-02-01)----------Supports Chrome v71-73
--------以下为2018年兼容版本对照表-------
ChromeDriver v2.45 (2018-12-10)----------Supports Chrome v70-72
ChromeDriver v2.44 (2018-11-19)----------Supports Chrome v69-71
ChromeDriver v2.43 (2018-10-16)----------Supports Chrome v69-71
ChromeDriver v2.42 (2018-09-13)----------Supports Chrome v68-70
ChromeDriver v2.41 (2018-07-27)----------Supports Chrome v67-69
ChromeDriver v2.40 (2018-06-07)----------Supports Chrome v66-68
ChromeDriver v2.39 (2018-05-30)----------Supports Chrome v66-68
ChromeDriver v2.38 (2018-04-17)----------Supports Chrome v65-67
ChromeDriver v2.37 (2018-03-16)----------Supports Chrome v64-66
ChromeDriver v2.36 (2018-03-02)----------Supports Chrome v63-65
ChromeDriver v2.35 (2018-01-10)----------Supports Chrome v62-64
chromedriver download address can go to http://chromedriver.storage.googleapis.com/index.html
The historical version of chrome can go to https://www.chromedownloads.net/chrome64linux-stable/
It doesn't matter if the version is older, as long as it matches.
Install chrome: (After downloading the chrome deb file to the server, execute it in this directory)
sudo dpkg -i google-chrome*.deb
执行sudo dpkg -i google-chrome*.deb后报错的话,
那就执行一下sudo apt-get install -f
再执行sudo dpkg -i google-chrome*.deb即可完美解决
安装后在/usr/bin目录下查看是否有google-chrome文件
Check the chrome version:
google-chrome --version
Install chromedriver:
After downloading the corresponding version
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
安装后查看/usr/bin目录下是否有chromedriver文件
Check the chromedriver version:
chromedriver -v
If you find that the version is wrong, chrome can be uninstalled like this:
yum remove google-chrome
chromedriver can directly delete the directory:
sudo rm -f /usr/bin/chromedriver
the third part
Finally, add the following code to the py file to run: (If you can run without adding it, then I do n’t say)
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=chrome_options)
The
"--no-sandbox" parameter is to allow Chrome to run with root privileges. The
"--headless" parameter is to open the graphical interface
Windows can refer to https://www.cnblogs.com/heguihui/p/10535526.html