在ubuntu服务器上使用Chrome Headless
Chrome
服务器安装Chrome
1 | # sudo apt-get install libxss1 libappindicator1 libindicator7 |
Chrome headless的启动
1 | google-chrome --headless --remote-debugging-port=9222 https://www.baidu.com --disable-gpu |
| param | description |
|---|---|
| headless | 无头模式 |
| remote-debugging-port | 调试端口 |
| disable-gpu | 禁止GPU |
访问本地调试端口,应看到调试信息
1 | curl http://localhost:9222 |
Chrome Driver
https://sites.google.com/a/chromium.org/chromedriver/downloads
http://npm.taobao.org/mirrors/chromedriver/
下载Chrome对应版本的Chrome Driver
报错
The process started from chrome location /usr/bin/google-chrome is no longer running
需要添加参数–disable-dev-shm-usage
测试
1 | from selenium import webdriver |
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 AlMirai!