安装chrome和chromedriver

学习爬虫安装 selenium 当然必不可少。

今天安装的时候踩了不少坑,所以记录一下

安装 chrome

两条命令即可,debian 系的安装 deb,Redhat 系安装 rpm 即可

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
apt install ./google-chrome-stable_current_amd64.deb

然后检查版本

google-chrome --version

安装 chromedriver

到淘宝镜像找到和 chrome 对应版本的 chromedriver

http://npm.taobao.org/mirrors/chromedriver/

然后右键复制链接,回到 linux,用 wget 下载。

wget http://npm.taobao.org/mirrors/chromedriver/87.0.4280.20/chromedriver_linux64.zip
然后解压,放到/usr/bin
unzip chromedriver_linux64.zip
mv chromedriver /usr/bin/
chmod +x /usr/bin/chromedriver

运行 selenium

刚开始运行 selenium 的时候,出了一堆报错,最后在 stackoverflow 上找到的解决办法。

设置以下 options

    chromeOptions.add_argument('--headless')
    chromeOptions.add_argument('--disable-gpu')
    chromeOptions.add_argument('--no-sandbox')
    b = webdriver.Chrome('/usr/bin/chromedriver', options=chromeOptions)
GitHub page:https://muryor.github.io/archives/5895b30f.html
posted @ 2020-12-04 20:05  olig48  阅读(216)  评论(0)    收藏  举报