1. chromedriver 下载地址: https://npm.taobao.org/mirrors/chromedriver
在这里找到对应的驱动
2. 安装谷歌浏览器
2.1 安装依赖
apt-get install libxss1 libappindicator1 libindicator7
2.2 下载Chrome安装包
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
2.3 安装
sudo dpkg -i google-chrome*.deb sudo apt-get install -f
3. 安装chromedriver
找到和浏览器对应的驱动
3.1 安装依赖
apt-get install unzip unzip chromedriver_linux64.zip mv -f chromedriver /usr/local/share/chromedriver
3.2 安装
#建立软连接ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
4. 测试
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument(‘--headless‘) options.add_argument(‘--no-sandbox‘) options.add_argument(‘--disable-dev-shm-usage‘) driver = webdriver.Chrome(executable_path="/usr/local/bin/chromedriver", chrome_options=options) print("======") driver.get(‘https://www.cnblogs.com/myvic/‘) print(driver.title) print(‘------------‘) driver.quit()
参考资料:
https://www.cnblogs.com/x54256/p/8403864.html
https://blog.csdn.net/qq551551/article/details/78885704/
原文地址:https://www.cnblogs.com/myvic/p/10324531.html
时间: 2024-10-09 05:29:03